A small toolkit for creating microservices.
Thanks: joho/godotenv
Create .env
file in the root of your project or run app with env variables.
TOKEN=ABC
PORT=8080
EXCHANGES=binance,bitfinex
DEBUG=true
Then in your Go app you can do something like:
import "github.com/Toscale-platform/kit/env"
token := env.GetString("TOKEN")
port := env.GetInt("PORT")
exchanges := env.GetSlice("EXCHANGES")
debug := env.GetBool("DEBUG")
Thanks: rs/zerolog
import "github.com/Toscale-platform/kit/log"
log.Error().Msg("Error message")
log.Info().Str("key", "value").Msg("Info message")
Thanks: valyala/fasthttp
import "github.com/Toscale-platform/kit/http"
http.Get("https://example.com", nil)
body := Body{}
http.Post("https://example.com", &body, nil)
Thanks: machinebox/graph
import (
"time"
"github.com/Toscale-platform/kit/http"
)
client := graphql.NewClient("https://machinebox.io/graphql")
req := graphql.NewRequest(`
query ($key: String!) {
items (id: $key) {
field1
field2
field3
}
}
`)
req.Var("key", "value")
req.Header.Set("Cache-Control", "no-cache")
var respData ResponseStruct
err := client.Run(req, &respData, time.Minute)
import "github.com/Toscale-platform/kit/validator"
if validator.IsExchange("binance") {
//
}
import "github.com/Toscale-platform/kit/output"
r := router.New()
r.GET("/path", handler)
r.OPTIONS("/path", output.CORSOptions)
func handler(ctx *fasthttp.RequestCtx){
res := map[string]string{"foo": "bar"}
output.JsonNoIndent(ctx, 200, res)
output.JsonMessageResult(ctx, 200, "message")
}
import "github.com/Toscale-platform/kit/auth"
r := router.New()
r.GET("/path", auth.IsAdmin(handler))