Skip to content

Commit 3545a81

Browse files
committed
init
0 parents  commit 3545a81

File tree

14 files changed

+705
-0
lines changed

14 files changed

+705
-0
lines changed

README.md

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Mojo take home test
2+
3+
It is crucial you read the "Your mission" section in full before you start. We recommend re-reading it before submitting.
4+
5+
Please do not fork this respository. Instead, clone it and push it to your own private repository. When you are ready to submit, please add the following users as collaborators to your repository, or download it as a ZIP for submission.
6+
7+
- https://github.com/DuffleOne
8+
- https://github.com/billinghamj
9+
10+
## Introduction
11+
12+
Hello and thank you for the time to contribute to the Mojo take home test! In this exercise we have a simple HTTP service that has a job to track sessions. A session represents a user on a device. The service has a few endpoints that allow us to query the sessions.
13+
14+
### `/list_by_platform`
15+
16+
This endpoint is given a platform, and returns a list of sessions associated with that platform.
17+
18+
### `/list_by_device_id`
19+
20+
This endpoint is given a device ID, and returns a list of sessions associated with that device.
21+
22+
## Your mission
23+
24+
### Part 1
25+
26+
The goal is to add a new endpoint that will return a list of all the sessions associated with a specific user ID. You will need to create the endpoint and register it within the service.
27+
28+
### Part 2
29+
30+
We now have 3 endpoints that all do very similiar things. What would it look like if we had just 1 endpoint with a flexible filter and pagination? Without changing the service code, what would the request struct look like? Write out just the struct as you would want it for that future endpoint.
31+
32+
## Requirements & grading criteria
33+
34+
* We will look for code that is minimal, clean, and readable.
35+
* We are keen on consistency and attention to detail.
36+
* We are looking for code that stylistically matches the rest of the codebase.
37+
* We are looking for your code to build if we run `go build ./...`
38+
* We are looking for you to spend no more than 20 to 30 minutes on this task.
39+
40+
* We are not looking for any testing, or automation or proof of correctness.
41+
* Do not worry about authentication.
42+
* Do not worry about marshalling structs or the HTTP transport layer. If you want to know more about how that works, review the CRPC package outside of the 20 minute allotted time.

cmd/mojo/main.go

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"net/http"
6+
"time"
7+
8+
"github.com/go-chi/chi/v5"
9+
"github.com/wearemojo/lead-be-task/session"
10+
"github.com/wearemojo/lead-be-task/session/app"
11+
"github.com/wearemojo/lead-be-task/session/db"
12+
"github.com/wearemojo/lead-be-task/session/service"
13+
"github.com/wearemojo/mojo-public-go/lib/clog"
14+
"github.com/wearemojo/mojo-public-go/lib/config"
15+
"github.com/wearemojo/mojo-public-go/lib/crpc"
16+
"github.com/wearemojo/mojo-public-go/lib/middleware/request"
17+
)
18+
19+
type ServerConfig struct {
20+
Logging clog.Config `json:"logging"`
21+
22+
Server config.Server `json:"server"`
23+
}
24+
25+
func main() {
26+
cfg := &ServerConfig{
27+
Logging: clog.Config{
28+
Format: "text",
29+
Debug: true,
30+
},
31+
32+
Server: config.Server{
33+
Addr: "127.0.0.1:3000",
34+
},
35+
}
36+
37+
log := cfg.Logging.Configure(context.Background())
38+
39+
var svc session.Service = &service.Service{App: &app.App{
40+
DB: db.New(context.Background()),
41+
}}
42+
43+
// create a new RPC server
44+
rpc := crpc.NewServer(unsafeNoAuthentication)
45+
46+
// add logging middleware
47+
rpc.Use(crpc.Logger())
48+
49+
rpc.Register("list_by_device_id", "2024-01-20", service.ListByDeviceIDSchema, svc.ListByDeviceID)
50+
rpc.Register("list_by_platform", "2024-01-20", service.ListByPlatformSchema, svc.ListByPlatform)
51+
52+
mux := chi.NewRouter()
53+
mux.Use(request.Logger(log))
54+
mux.With(request.StripPrefix("/v1")).Handle("/v1/*", rpc)
55+
56+
httpServer := &http.Server{
57+
Handler: mux,
58+
ReadHeaderTimeout: 10 * time.Second,
59+
}
60+
61+
log.WithField("addr", cfg.Server.Addr).Info("listening")
62+
if err := cfg.Server.ListenAndServe(httpServer); err != nil {
63+
log.WithError(err).Fatal("listen failed")
64+
}
65+
}
66+
67+
func unsafeNoAuthentication(next crpc.HandlerFunc) crpc.HandlerFunc {
68+
return func(res http.ResponseWriter, req *crpc.Request) error {
69+
return next(res, req)
70+
}
71+
}

go.mod

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
module github.com/wearemojo/lead-be-task
2+
3+
go 1.21.5
4+
5+
require (
6+
github.com/go-chi/chi/v5 v5.0.11
7+
github.com/wearemojo/mojo-public-go v0.0.0-20240119160407-110d998b669a
8+
github.com/xeipuuv/gojsonschema v1.2.0
9+
go.mongodb.org/mongo-driver v1.13.1
10+
)
11+
12+
require (
13+
cloud.google.com/go/compute v1.23.3 // indirect
14+
cloud.google.com/go/compute/metadata v0.2.3 // indirect
15+
github.com/blang/semver/v4 v4.0.0 // indirect
16+
github.com/cespare/xxhash/v2 v2.2.0 // indirect
17+
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
18+
github.com/felixge/httpsnoop v1.0.4 // indirect
19+
github.com/go-logr/logr v1.4.1 // indirect
20+
github.com/go-logr/stdr v1.2.2 // indirect
21+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
22+
github.com/golang/protobuf v1.5.3 // indirect
23+
github.com/golang/snappy v0.0.4 // indirect
24+
github.com/google/go-cmp v0.6.0 // indirect
25+
github.com/google/s2a-go v0.1.7 // indirect
26+
github.com/google/uuid v1.5.0 // indirect
27+
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
28+
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
29+
github.com/jamescun/basex v0.0.0-20180407124237-e1bcb39ab18e // indirect
30+
github.com/klauspost/compress v1.17.4 // indirect
31+
github.com/montanaflynn/stats v0.7.1 // indirect
32+
github.com/pkg/errors v0.9.1 // indirect
33+
github.com/redis/go-redis/v9 v9.4.0 // indirect
34+
github.com/sirupsen/logrus v1.9.3 // indirect
35+
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
36+
github.com/xdg-go/scram v1.1.2 // indirect
37+
github.com/xdg-go/stringprep v1.0.4 // indirect
38+
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
39+
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
40+
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
41+
go.opencensus.io v0.24.0 // indirect
42+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.47.0 // indirect
43+
go.opentelemetry.io/otel v1.22.0 // indirect
44+
go.opentelemetry.io/otel/metric v1.22.0 // indirect
45+
go.opentelemetry.io/otel/trace v1.22.0 // indirect
46+
golang.org/x/crypto v0.18.0 // indirect
47+
golang.org/x/net v0.20.0 // indirect
48+
golang.org/x/oauth2 v0.16.0 // indirect
49+
golang.org/x/sync v0.6.0 // indirect
50+
golang.org/x/sys v0.16.0 // indirect
51+
golang.org/x/text v0.14.0 // indirect
52+
google.golang.org/api v0.157.0 // indirect
53+
google.golang.org/appengine v1.6.8 // indirect
54+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac // indirect
55+
google.golang.org/grpc v1.60.1 // indirect
56+
google.golang.org/protobuf v1.32.0 // indirect
57+
gopkg.in/ini.v1 v1.67.0 // indirect
58+
)

0 commit comments

Comments
 (0)