BITLY_OAUTH_TOKEN
- used to have access to bitly API. Has to be set for common start and for tests in pkg/bitly
.
GRPC_HOST_PORT
- has to be set only for integration tests in tests
directory to specify address of running gRPC server.
Cobra CLI is implemented for cmd/client
application to perform manual testing of all gRPC endpoints.
General flags: address
- gRPC address of targeted server. (default: localhost:6000
)
Commands:
metadata --meta=RandomMetadata
- manual call for ReadMetadata endpoint.
shortener --url=https://google.com
- manual call for MakeShortLink endpoint.
timer --name=TimerName --freq=2 --secs=10
- manual call for StartTimer endpoint.
Example usage: go run cmd/client/main.go metadata --meta=RandomString
cmd
server
- entrypoint of main gRPC server.client
- entrypoint of cli application.
pkg
api
bitly
- package of integration with Bitly HTTP API.timercheck
- package of integration with Timercheck.io HTTP API.
cli
- command files of Cobra CLI.config
- parser of configuration data using Viper.proto
- .protobuf files and autogenerated code from .proto files.timer
- stores functionality to create/subscribe to timer channels.grpc/challenge_server
- gRPC endpoints implementation.
configs
- place to store configuration files.tests
- integration tests.
The image is tested in Github Actions and pushed to ghcr.io
.
Image size is 17MB.
- Go-lang
- gRPC / gRPC-Streaming
- gRPC Metadata
- HTTP(REST)
- Go testing
- Docker
- Console and CLI tools
Read through all the tasks and notes before solving.
- Fork this repo
- Clone -> Now you can push your changes
- Install buf and generate code from proto
- Make gRPC Server base:
main.go
incmd/server
, server methods inpkg/server
- Comments and docs are appreciated :)
- Read environment vars: task description
- Make Metadata reader method: task description
- Make link shortener method: task description
- Make link metadata test(s): task description
- Make Timer Streaming method: task description
- Make it running in Docker: task description
- Make link shortener test(s): task description
- Make
cmd/client
using cobra
- Make Timer Streaming test: task description
- Gituhub - Publish, test and CI: task description
- Along with
cmd/server
-cmd/client
has to be provided. This would be used for manual endpoints testing. - Protobuf messages structure(s) can be edited in anyway you'd need(for example to match external APIs responses)
- All dependencies should be logged and provided in
go.mod
(seego mod tidy
)
main.go
must read environment variables using viper and store it accesible by server scope. As the variable to read, use BITLY_OAUTH_LOGIN
and BITLY_OAUTH_TOKEN
, you'll need them in the next task
Each gRPC call has context. And Outgoing and Incoming context can be appended to it.
Implement ChallengeService.ReadMetadata
method. It has to read i-am-random-key
from context metadata and return it in the Response data as string.
Implement server method test using *testing.T
. Test should make request with random string in metadata i-am-random-key
key and ensure it's being returned so.
Using Bitly API, implement ChallengeService.MakeShortLink
method. It has to receive long link and return short bit.ly link.
API calls has to be implemented with net/http
.
You need to register at bit.ly to get token and username
Implement server method test using *testing.T
and net/http
. Test should generate link using server method and ensure short-link actually leads to given link(see http statuses and follow-redirects).
Additional tests covering bit.ly API edge scenarious are welcomed.
Note: Tests must be checking methods over network and read server location from environment
Using this API or simillar implement streaming endpoint ChallengeService.StartTimer
.
Endpoint accepts message with amount of Seconds timer should run, frequency of refresh requests in seconds. Endpoint should do refresh every freqency
seconds and send amount of seconds left back to stream and name for the new Timer.
Every new client trying to start a timer with the name of existing timer should be automatically subscribed to existing one.
Implement server method test using *testing.T
.
Test should cover:
- Client reconnect - client must be resubscribed to the same timer
- Additional client - new client must be subscribed to the same timer as the old client and receive same (amount of) messages
Note: Tests must be checking methods over network and read server location from environment
Write Dockerfile
for this project.
Requirements:
1. Each step of preparation and build has to be happening in a Docker-runtime
2. Image has to be as lightweight as possible
Publish this project to Github repo.
Set Github Actions Workflow called ci.yml
.
Workflow must:
- Build Docker Image
- Start Docker Container
- Run tests with this container
- Publish Docker Image to
ghcr.io
(Github Packages of your repo)
You should store bit.ly credentials in Repo secrets