Skip to content

Commit

Permalink
feat: add generic API calls
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Nov 30, 2019
1 parent bce3a94 commit 6dae06b
Show file tree
Hide file tree
Showing 15 changed files with 7,444 additions and 3,555 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
data/db.sqlite
coverage.txt

static/img/cache
Expand Down
146 changes: 71 additions & 75 deletions api/calcapi.proto
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ service Service {
rpc SoundcloudPlaylist(SoundcloudPlaylist.Input) returns (SoundcloudPlaylist.Output) { option (google.api.http) = {get: "/api/soundcloud/playlists/{playlist_id}"}; }
rpc SoundcloudTracks(SoundcloudTracks.Input) returns (SoundcloudTracks.Output) { option (google.api.http) = {get: "/api/soundcloud/tracks"}; }
rpc SoundcloudTrack(SoundcloudTrack.Input) returns (SoundcloudTrack.Output) { option (google.api.http) = {get: "/api/soundcloud/tracks/{track_id}"}; }
rpc Metrics(Metrics.Input) returns (Metrics.Output) {option (google.api.http) = {get: "/api/metrics"};}
rpc Metrics(Metrics.Input) returns (Metrics.Output) { option (google.api.http) = {get: "/api/metrics"};}
rpc CounterInc(CounterInc.Input) returns (CounterInc.Output) { option (google.api.http) = {get: "/api/counter-inc/{key}"}; };
rpc NumberSetIfBigger(NumberSetIfBigger.Input) returns (NumberSetIfBigger.Output) { option (google.api.http) = {get: "/api/number-set-if-bigger/{key}/{value}"}; };
rpc KeyValueStringSet(KeyValueStringSet.Input) returns (KeyValueStringSet.Output) { option (google.api.http) = { post: "/api/key-value-string-set/{key}"; body: "*" }; };
rpc KeyValueStringGet(KeyValueStringGet.Input) returns (KeyValueStringGet.Output) { option (google.api.http) = { get: "/api/key-value-string-get/{key}"}; };
rpc KeyValueFloatSet(KeyValueFloatSet.Input) returns (KeyValueFloatSet.Output) { option (google.api.http) = { post: "/api/key-value-float-set/{key}"; body: "*" }; };
rpc KeyValueFloatGet(KeyValueFloatGet.Input) returns (KeyValueFloatGet.Output) { option (google.api.http) = { get: "/api/key-value-float-get/{key}"}; };

// SoundcloudAlbums
// Airtable...
Expand All @@ -44,68 +50,78 @@ service Service {
// Genius...
}

message CounterInc {
message Input { string key = 1; double gap = 2; }
message Output { double value = 2; }
}

message NumberSetIfBigger {
message Input { string key = 1; double value = 2; }
message Output { double value = 2; }
}

message KeyValueStringSet {
message Input { string key = 1; string value = 2; }
message Output {}
}

message KeyValueStringGet {
message Input { string key = 1; }
message Output { string value = 2; }
}

message KeyValueFloatSet {
message Input { string key = 1; double value = 2; }
message Output {}
}

message KeyValueFloatGet {
message Input { string key = 1; }
message Output { double value = 2; }
}

message Dashboard {
message Input {}
message Output {
calcbiz.dashboard.Entries entries = 1;
}
message Input {}
message Output { calcbiz.dashboard.Entries entries = 1; }
}

message Hackz {
message Input {}
message Output {
calcbiz.dashboard.Entries entries = 1;
}
message Input {}
message Output { calcbiz.dashboard.Entries entries = 1; }
}

message Crew {
message Input {}
message Output {
calcbiz.crew.Crew crew = 1;
}
message Input {}
message Output { calcbiz.crew.Crew crew = 1; }
}

message SoundcloudMe {
message Input {}
message Output {
calcbiz.soundcloud.User me = 1;
}
message Input {}
message Output { calcbiz.soundcloud.User me = 1; }
}

message SoundcloudPlaylists {
message Input {}
message Output {
calcbiz.soundcloud.Playlists playlists = 1;
}
message Input {}
message Output { calcbiz.soundcloud.Playlists playlists = 1; }
}

message SoundcloudPlaylist {
message Input {
uint64 playlist_id = 1;
}
message Output {
calcbiz.soundcloud.Playlist playlist = 1;
}
message Input { uint64 playlist_id = 1; }
message Output { calcbiz.soundcloud.Playlist playlist = 1; }
}

message SoundcloudTracks {
message Input {}
message Output {
calcbiz.soundcloud.Tracks tracks = 1;
}
message Input {}
message Output { calcbiz.soundcloud.Tracks tracks = 1; }
}

message SoundcloudTrack {
message Input {
uint64 track_id = 1;
}
message Output {
calcbiz.soundcloud.Track track = 1;
}
message Input { uint64 track_id = 1; }
message Output { calcbiz.soundcloud.Track track = 1; }
}

message Metrics {
message Input {}
message Input {}
message Output {
int32 static_box_size = 1;
string server_start_time = 2;
Expand All @@ -116,72 +132,52 @@ message Metrics {
}

message Ping {
message Input {}
message Output {
string pong = 1;
}
message Input {}
message Output { string pong = 1; }
}

message Kryptos {
message Input {
string from = 1;
}
message Output {
string to = 1;
}
message Input { string from = 1; }
message Output { string to = 1; }
}

message TpyoEnocde {
message Ipunt {
string form = 1;
}
message Ouptut {
string to = 1;
}
message Ipunt { string form = 1; }
message Ouptut { string to = 1; }
}

message Numberinfo {
message Input {
float number = 1;
}
message Output {
map<string, string> facts = 1;
}
message Input { float number = 1; }
message Output { map<string, string> facts = 1; }
}

message Moijaime {
message Input {}
message Output {
repeated string kiffs = 1;
}
message Input {}
message Output { repeated string kiffs = 1; }
}

message Wotd {
message Input {}
message Output {
string word = 1;
}
message Input {}
message Output { string word = 1; }
}

message AlternateLogo {
message Input {}
message Output {
string path = 1;
}
message Input {}
message Output { string path = 1; }
}

message SpreadshirtRandom {
message Input {}
message Input {}
message Output { /* TODO */ }
}

message SpreadshirtAll {
message Input {}
message Input {}
message Output { /* TODO */ }
}

message Recettator {
message Input {
message Input {
int64 seed = 1;
uint64 main_ingredients = 2;
uint64 secondary_ingredients = 3;
Expand Down
10 changes: 9 additions & 1 deletion cmd/calcbiz/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
grpc_recovery "github.com/grpc-ecosystem/go-grpc-middleware/recovery"
grpc_ctxtags "github.com/grpc-ecosystem/go-grpc-middleware/tags"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite" // db driver
"github.com/pkg/errors"
minify "github.com/tdewolff/minify/v2"
"github.com/tdewolff/minify/v2/html"
Expand Down Expand Up @@ -141,7 +143,13 @@ func server(c *cli.Context) error {

opts := serverOptionsFromCliContext(c)

svc, err := calcapi.New(opts.APIOptions)
db, err := gorm.Open("sqlite3", "./data/db.sqlite")
if err != nil {
return errors.Wrap(err, "init gorm")
}
defer db.Close()

svc, err := calcapi.New(db, opts.APIOptions)
if err != nil {
return errors.Wrap(err, "failed to initialize service")
}
Expand Down
Empty file added data/.gitkeep
Empty file.
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ services:
networks:
- default
- service-proxy
volumes:
- ./data:/data

networks:
service-proxy:
Expand Down
2 changes: 1 addition & 1 deletion gen.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
01de06cfe2c7566d9894afbf15ac8dd904623f90 ./api/calcapi.proto
431b63cd908588e398bbb94d1e642e585441099c ./api/dashboard.proto
5c613daf5318661d709f8766163ef986d885b72d Makefile
a0415fc5002d339337b03fe97801376ff3be3bbd ./api/crew.proto
ee9a45d94f6e289cd401af8714514f678de7f314 ./api/calcapi.proto
ffa8325482af5c58dd816e9404f0226db0a1d7de ./api/soundcloud.proto
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
github.com/grpc-ecosystem/grpc-gateway v1.12.1
github.com/huandu/xstrings v1.2.1 // indirect
github.com/imdario/mergo v0.3.8 // indirect
github.com/jinzhu/gorm v1.9.11
github.com/jtolds/gls v4.2.1+incompatible // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mitchellh/reflectwalk v1.0.1 // indirect
Expand Down
Loading

0 comments on commit 6dae06b

Please sign in to comment.