Skip to content

Commit

Permalink
feat: port more endpoints to gRPC
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Jan 15, 2019
1 parent 42c41d1 commit 9a131f0
Show file tree
Hide file tree
Showing 11 changed files with 311 additions and 199 deletions.
408 changes: 274 additions & 134 deletions api/api.pb.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions api/api.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions api/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ service Server {
};
rpc TpyoEnocde(TpyoEnocdeIpunt) returns (TpyoEnocdeOuptut) {
option (google.api.http) = {
post: "/api/spreadshirt/all"
post: "/api/tpyo"
body: "*"
}; }

Expand Down Expand Up @@ -62,11 +62,11 @@ message Void {}
message Pong { string pong = 1; }
message KryptosInput { string from = 1; }
message KryptosOutput { string to = 1; }
message TpyoEnocdeIpunt { string from = 1; }
message TpyoEnocdeIpunt { string form = 1; }
message TpyoEnocdeOuptut { string to = 1; }
message DahsboardRandomOutput { /* TODO */ }
message NumberinfoInput { string number = 1; }
message NumberinfoOutput { /* TODO */ }
message NumberinfoInput { float number = 1; }
message NumberinfoOutput { map<string, string> facts = 1; }
message MoijaimeOutput { repeated string kiffs = 1; }
message WotdOutput { string word = 1; }
message AlternateLogoOutput { string path = 1; }
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ require (
github.com/sirupsen/logrus v1.3.0 // indirect
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d // indirect
github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c // indirect
github.com/tpyolang/tpyo-cli v1.0.0
github.com/urfave/cli v1.20.0
github.com/yanatan16/golang-soundcloud v0.0.0-20161013200625-a182dd459b66
go.uber.org/atomic v1.3.2 // indirect
go.uber.org/multierr v1.1.0 // indirect
go.uber.org/zap v1.9.1
golang.org/x/net v0.0.0-20190110044637-be1c187aa6c6
google.golang.org/appengine v1.2.0 // indirect
google.golang.org/genproto v0.0.0-20190108161440-ae2f86662275
google.golang.org/grpc v1.17.0
ultre.me/kryptos v0.0.0-20181023194748-240fe1a16033
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ github.com/spf13/viper v1.3.1/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DM
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/tpyolang/tpyo-cli v1.0.0 h1:vf0ddfW9Si2pn3rzPe51hFpWmvkkVZNWnmXLIsAe2gg=
github.com/tpyolang/tpyo-cli v1.0.0/go.mod h1:gYyKr7Mog1FDfbA58jt3iYlcUZY5ztHkHjioIDLuu1w=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/unrolled/secure v0.0.0-20180918153822-f340ee86eb8b/go.mod h1:mnPT77IAdsi/kV7+Es7y+pXALeV3h7G6dQF6mNYjcLA=
github.com/unrolled/secure v0.0.0-20181005190816-ff9db2ff917f/go.mod h1:mnPT77IAdsi/kV7+Es7y+pXALeV3h7G6dQF6mNYjcLA=
Expand Down
2 changes: 1 addition & 1 deletion pkg/crew/crew.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package crew
package crew // import "ultre.me/calcbiz/pkg/crew"

var CALC = Crew{
Name: "Camembert au lait crew",
Expand Down
8 changes: 4 additions & 4 deletions pkg/dashboard/dashboard.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package calcdashboard
package dashboard // import "ultre.me/calcbiz/pkg/dashboard"

import (
"fmt"
Expand All @@ -9,7 +9,7 @@ import (
)

type CALCDashboard struct {
soundcloud *calcsoundcloud.CALCSoundcloud
soundcloud *soundcloud.Soundcloud
}

const (
Expand All @@ -22,7 +22,7 @@ func New() *CALCDashboard {
return &CALCDashboard{}
}

func (d *CALCDashboard) SetSoundCloud(soundcloud *calcsoundcloud.CALCSoundcloud) {
func (d *CALCDashboard) SetSoundCloud(soundcloud *soundcloud.Soundcloud) {
d.soundcloud = soundcloud
}

Expand Down Expand Up @@ -66,7 +66,7 @@ func (d *CALCDashboard) trackEntries(limit int) (Entries, error) {
func (d *CALCDashboard) merchEntries(limit int) (Entries, error) {
entries := Entries{}

products := calcspreadshirt.GetAllProducts(250, 250)
products := spreadshirt.GetAllProducts(250, 250)
if len(products) < limit {
limit = len(products)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/numberinfo/numberinfo.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package calcnumberinfo
package numberinfo // import "ultre.me/calcbiz/pkg/numberinfo"

import (
"math"
Expand Down
2 changes: 1 addition & 1 deletion pkg/random/random.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package calcrand
package random // import "ultre.me/calcbiz/pkg/random"

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion pkg/spreadshirt/spreadshirt.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package calcspreadshirt
package spreadshirt // import "ultre.me/calcbiz/pkg/spreadshirt"

import (
"fmt"
Expand Down
70 changes: 19 additions & 51 deletions svc/svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import (
"context"
"fmt"

tpyo "github.com/tpyolang/tpyo-cli"
"ultre.me/calcbiz/api"
"ultre.me/calcbiz/pkg/crew"
"ultre.me/calcbiz/pkg/numberinfo"
"ultre.me/calcbiz/pkg/random"
"ultre.me/calcbiz/pkg/soundcloud"
"ultre.me/kryptos"
)
Expand Down Expand Up @@ -49,24 +52,10 @@ func (svc *svc) KryptosDecrypt(_ context.Context, input *api.KryptosInput) (*api
}

func (svc *svc) TpyoEnocde(_ context.Context, input *api.TpyoEnocdeIpunt) (*api.TpyoEnocdeOuptut, error) {
/*
r.Post("/tpyo/enocde", func(w http.ResponseWriter, r *http.Request) {
var data struct {
Message string
}
if err := c.BindJSON(&data); err == nil {
enedocr := tpyo.NewTpyo()
c.JSON(http.StatusOK, gin.H{
"result": enedocr.Enocde(data.Message),
})
} else {
c.JSON(http.StatusNotFound, gin.H{
"error": fmt.Sprintf("Invalid input: %v", err),
})
}
})
*/
return nil, fmt.Errorf("not implemented")
enedocr := tpyo.NewTpyo()
return &api.TpyoEnocdeOuptut{
To: enedocr.Enocde(input.Form),
}, nil
}

func (svc *svc) Dashboard(_ context.Context, input *api.Void) (*api.DashboardOutput, error) {
Expand All @@ -92,23 +81,12 @@ func (svc *svc) Crew(_ context.Context, input *api.Void) (*crew.Crew, error) {
}

func (svc *svc) Numberinfo(_ context.Context, input *api.NumberinfoInput) (*api.NumberinfoOutput, error) {
/*
r.Get("/numberinfo/all/:number", func(w http.ResponseWriter, r *http.Request) {
number, err := strconv.ParseFloat(c.Param("number"), 64)
if err != nil {
c.JSON(http.StatusNotFound, gin.H{
"error": fmt.Sprintf("Invalid number: %v (%v)", c.Param("number"), err),
})
return
}
info := calcnumberinfo.New(number).All()
c.JSON(http.StatusOK, gin.H{
"result": info,
})
})
*/
return nil, fmt.Errorf("not implemented")
// FIXME: validate: input.Number is mandatory
facts := map[string]string{}
for k, v := range numberinfo.New(float64(input.Number)).All() {
facts[k] = fmt.Sprintf("%v", v)
}
return &api.NumberinfoOutput{Facts: facts}, nil
}

func (svc *svc) Recettator(_ context.Context, input *api.RecettatorInput) (*api.RecettatorOutput, error) {
Expand Down Expand Up @@ -177,25 +155,15 @@ func (svc *svc) SpreadshirtAll(_ context.Context, input *api.Void) (*api.Spreads
}

func (svc *svc) Wotd(_ context.Context, input *api.Void) (*api.WotdOutput, error) {
/*
r.Get("/random/wotd", func(w http.ResponseWriter, r *http.Request) {
c.JSON(http.StatusOK, gin.H{
"result": calcrand.WOTD(),
})
})
*/
return nil, fmt.Errorf("not implemented")
return &api.WotdOutput{
Word: random.WOTD(),
}, nil
}

func (svc *svc) AlternateLogo(_ context.Context, input *api.Void) (*api.AlternateLogoOutput, error) {
/*
r.Get("/random/alternate-logo", func(w http.ResponseWriter, r *http.Request) {
c.JSON(http.StatusOK, gin.H{
"result": calcrand.AlternateLogo(),
})
})
*/
return nil, fmt.Errorf("not implemented")
return &api.AlternateLogoOutput{
Path: random.AlternateLogo(),
}, nil
}

func (svc *svc) SoundcloudMe(_ context.Context, input *api.Void) (*soundcloud.User, error) {
Expand Down

0 comments on commit 9a131f0

Please sign in to comment.