suki

package module
v0.0.0-...-ac9c04b Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2019 License: MIT Imports: 33 Imported by: 0

README

Suki

Understanding the Japanese Word "Suki" The common Japanese word suki, pronounced "suh-kee", means a liking of, or fondness for; it means you love something or have a taste for that thing

  • Use a Log
package main
import (
    "github.com/ae-gis/suki"
)

func main(){
    
    suki.Error("Error",
        suki.Field("error", "error for log"),
    )
    suki.Debug("Debug",
        suki.Field("debug", "debug for log"),
        suki.Field("message", "message debug for log"),
    )
    suki.Info("Info",
        suki.Field("info", "info for log"),
        suki.Field("message", "message info for log"),
    )
    suki.Warn("Warn",
        suki.Field("warning", "warning for log"),
        suki.Field("message", "message warning for log"),
    )
        
    log := suki.With(suki.Field("Root", "Messaging"))
    log.Debug("Debug",
        suki.Field("debug", "debug for log"),
        suki.Field("message", "message debug for log"),
    )
    log.Info("Info",
        suki.Field("info", "info for log"),
        suki.Field("message", "message info for log"),
    )

}

  • Use a Http Serve
package main
import (
     "fmt"
     "html"
     "net/http"
     "github.com/ae-gis/suki"
)

func main(){
        handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
                   _, err := fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
                   if err != nil {
                           panic(err)
                   }
        })
        s := suki.NewCmdHttp(8009, 100, 10, handler).GetCmd()
        if err := s.Execute(); err != nil {
                panic(err)
        }
}

  • Use a Breaker
package main
import (
    "net/http"
    "github.com/hashicorp/go-cleanhttp"
    "github.com/ae-gis/suki"
)

func main() {
    endpoint := `www.google.com`
    cb := suki.NewBreaker(
        "",
        100,
        10,
    )
    var res *http.Response
    err := cb.Execute(func() (err error) {
        client := cleanhttp.DefaultClient()
        req, _ := http.NewRequest(http.MethodGet,
            endpoint, nil)
        res, err = client.Do(req)
        return err
    })
    if err != nil {
        suki.Error("Error",
            suki.Field("error", err.Error()),
        )
        panic(err)
    }
}

Documentation

Index

Constants

View Source
const (
	RecommendedRoundsSHA1   = 131000
	RecommendedRoundsSHA256 = 29000
	RecommendedRoundsSHA512 = 25000
)
View Source
const (
	StatusSuccess               = http.StatusOK
	StatusErrorForm             = http.StatusBadRequest
	StatusErrorUnknown          = http.StatusBadGateway
	StatusInternalError         = http.StatusInternalServerError
	StatusUnauthorized          = http.StatusUnauthorized
	StatusCreated               = http.StatusCreated
	StatusAccepted              = http.StatusAccepted
	StatusForbidden             = http.StatusForbidden
	StatusInvalidAuthentication = http.StatusProxyAuthRequired
)

Variables

View Source
var CtxResponse = ctxKeyResponse{Name: "context response"}

Functions

func Base64Decode

func Base64Decode(src string) (dst []byte)

Base64Encode decodes using a Standard of base64. return string base64 encode

func Base64Encode

func Base64Encode(src []byte) (dst string)

Base64Encode encodes using a Standard of base64. return string base64 encode

func DateRangeValidation

func DateRangeValidation(fl validator.FieldLevel) bool

func DateValidation

func DateValidation(fl validator.FieldLevel) bool

func DatetimeValidation

func DatetimeValidation(fl validator.FieldLevel) bool

func Debug

func Debug(msg string, fields ...interface{})

func Error

func Error(msg string, fields ...interface{})

func Fatal

func Fatal(msg string, fields ...interface{})

func Field

func Field(key string, value interface{}) interface{}

func GenerateChar

func GenerateChar(length int) string

GenerateVoucher Generate Voucher using Alphanumeric except O & 0 return as String

func HashPassword

func HashPassword(password, salt string) string

func Info

func Info(msg string, fields ...interface{})

func Instance

func Instance() *zapLog

func NewZap

func NewZap(c Core) *zapLog

New creates new instance of zapLog

func NewZapProductionEncoderConfig

func NewZapProductionEncoderConfig() zapcore.EncoderConfig

func Panic

func Panic(msg string, fields ...interface{})

func ParseDate

func ParseDate(dtStr string) time.Time

func ParseDatetime

func ParseDatetime(dtStr string) time.Time

func PassLibBase64Decode

func PassLibBase64Decode(src string) (dst []byte, err error)

PassLibBase64Decode decodes using a variant of base64, like Passlib. Check https://pythonhosted.org/passlib/lib/passlib.utils.html#passlib.utils.ab64_decode

func PassLibBase64Encode

func PassLibBase64Encode(src []byte) (dst string)

PassLibBase64Encode encodes using a variant of base64, like Passlib. Check https://pythonhosted.org/passlib/lib/passlib.utils.html#passlib.utils.ab64_encode

func Response

func Response() *response

func Status

func Status(r *http.Request, status int)

func StatusCode

func StatusCode(code int) string

func StatusText

func StatusText(code int) string

func ToCamel

func ToCamel(s string) string

ToCamel converts a string to CamelCase

func UUID

func UUID() string

UUID returns a newly initialized string object that implements the UUID interface.

func Velkommen

func Velkommen() string

func VerifyPassword

func VerifyPassword(hashpassword, password string) (bool, error)

func Warn

func Warn(msg string, fields ...interface{})

func WriteCSV

func WriteCSV(w http.ResponseWriter, r *http.Request, rows [][]string, filename string)

func WriteJSON

func WriteJSON(w http.ResponseWriter, r *http.Request, v interface{})

Write writes the data to http response writer

Types

type CircuitBreaker

type CircuitBreaker struct {
	// contains filtered or unexported fields
}

func NewBreaker

func NewBreaker(name string, timeout, maxConcurrent int, args ...interface{}) *CircuitBreaker

SetCommandBreaker the circuit breaker

func (*CircuitBreaker) Execute

func (cb *CircuitBreaker) Execute(fn func() error) (err error)

callBreaker command circuit breaker

type CmdHttp

type CmdHttp interface {
	GetCmd() *cobra.Command
	GRPCHandler(handler *grpc.Server)
	// contains filtered or unexported methods
}

func NewCmdHttp

func NewCmdHttp(handler http.Handler, port, readTimeout, writeTimeout int) CmdHttp

func NewCmdHttpSignaled

func NewCmdHttpSignaled(
	handler http.Handler,
	port,
	readTimeout,
	writeTimeout int,
	stop <-chan bool,
) CmdHttp

type Core

type Core = zapcore.Core

func DefaultCore

func DefaultCore(out zapcore.WriteSyncer) Core

func ProductionCore

func ProductionCore() Core

type Logging

type Logging interface {
	With(fields ...interface{}) Logging
	Debug(msg string, fields ...interface{})
	Info(msg string, fields ...interface{})
	Warn(msg string, fields ...interface{})
	Error(msg string, fields ...interface{})
	Fatal(msg string, fields ...interface{})
	Panic(msg string, fields ...interface{})
	Field(key string, value interface{}) interface{} // for type fields
}

func With

func With(fields ...interface{}) Logging

type Meta

type Meta struct {
	Code    string `json:"code,omitempty"`
	Type    string `json:"error_type,omitempty"`
	Message string `json:"error_message,omitempty"`
}

func Validate

func Validate(s interface{}) (errors []Meta)

type Pagination

type Pagination struct {
	Page  int `json:"page"`
	Size  int `json:"size"`
	Total int `json:"total"`
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server warps http.Server.

func StartWebServer

func StartWebServer(addr url.URL, readTimeout, writeTimeout int, handler http.Handler) *Server

StartWebServer starts a web server

func (*Server) Stop

func (srv *Server) Stop()

Stop stops the server. Useful for testing.

func (*Server) StopNotify

func (srv *Server) StopNotify() <-chan struct{}

StopNotify returns receive-only stop channel to notify the server has stopped.

type ZapField

type ZapField = zapcore.Field

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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