Categorygithub.com/Toscale-platform/kit
repository
1.5.17
Repository: https://github.com/toscale-platform/kit.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# README

Toscale Kit

Go Report Card Go Reference

A small toolkit for creating microservices.

Packages:

Env

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")

Log

Thanks: rs/zerolog

import "github.com/Toscale-platform/kit/log"

log.Error().Msg("Error message")
log.Info().Str("key", "value").Msg("Info message")

HTTP

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)

GraphQL

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)

Validator

import "github.com/Toscale-platform/kit/validator"

if validator.IsExchange("binance") {
    //
}

Output

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")
}

Auth

import "github.com/Toscale-platform/kit/auth"

r := router.New()

r.GET("/path", auth.IsAdmin(handler))