toscale-kit

module
v1.4.7 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: MIT

README

Toscale Kit

A small toolkit for creating microservices

Packages:

Env

Main library: spf13/viper

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:

package main

import "github.com/Toscale-platform/toscale-kit/env"

func main() {
    token := env.GetString("TOKEN")
    port := env.GetInt("PORT")
    exchanges := env.GetSlice("EXCHANGES")
    debug := env.GetBool("DEBUG")
}
Log

Main library: rs/zerolog

package main

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

func main() {
    log.Error().Msg("Error message")
    log.Info().Str("key", "value").Msg("Info message")
}
HTTP

Main library: valyala/fasthttp

package main

import "github.com/Toscale-platform/toscale-kit/http"

func main() {
    http.Get("https://example.com", nil)

    body := Body{}
    http.Post("https://example.com", &body, nil)
}
Validator
package main

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

func main() {
    if validator.IsSymbol("BTC/USDT") {
        //
    }
	
    if validator.IsExchange("binance") {
        //
    }
}
Output
package main

import "github.com/Toscale-platform/toscale-kit/output"

func main() {
    r := router.New()
	
    r.GET("/path", handler)
    r.OPTIONS("/path", output.CORSOptions)
}

func handler(ctx *fasthttp.RequestCtx){
    res := interface{}

    output.OutputJson(ctx, 200, res)
    output.JsonNoIndent(ctx, 200, res)
	
    output.JsonMessageResult(ctx, 200, "message")
}
Auth
package main

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

func main() {
    isDebug := env.GetBool("DEBUG")
    host := env.GetString("AUTH_HOST")
    authManager := auth.Init(host, isDebug)
    
    r := router.New()
    
    r.GET("/path", authManager.IsAdmin(handler))
}
Exchange
package main

import "github.com/Toscale-platform/toscale-kit/exchange"

func main() {
    symbols, err := exchange.GetSymbols("binance")
    if err != nil {
        //
    }
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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