kit

module
v1.5.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 22, 2024 License: MIT

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

Thanks: go-playground/validator

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

if validator.Is("email@example.com", "required,email") {
	//
}

if validator.IsSymbol("BTC/USDT") {
    //
}

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"

isDebug := env.GetBool("DEBUG")
host := env.GetString("AUTH_HOST")
authManager := auth.Init(host, isDebug)

r := router.New()

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL