core

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2022 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Pass  = 0
	Deny  = 1
	Error = 2
)

response code

Variables

View Source
var (
	AssetDir string
	Gwg      sync.WaitGroup
)

Trans Translator

View Source
var Validate *validator.Validate

Validate use a single instance of Validate, it caches struct info

Functions

func CreateValidator

func CreateValidator()

CreateValidator create a single Validator

func GetAssetDir

func GetAssetDir() string

GetAssetDir if env = 'production' return absolute else return relative

func GetConfigFile added in v1.2.0

func GetConfigFile() string

func GetDBFile added in v1.3.0

func GetDBFile() string

func Log

func Log(lv LogLevel, content string)

Log information to file with logged day

Types

type Goploy

type Goploy struct {
	Request        *http.Request
	ResponseWriter http.ResponseWriter
	URLQuery       url.Values
	Body           []byte
}

Goploy callback param

type LogLevel

type LogLevel string

LogLevel is log level

const (
	TRACE   LogLevel = "TRACE: "
	WARNING LogLevel = "WARNING: "
	INFO    LogLevel = "INFO: "
	ERROR   LogLevel = "ERROR: "
)

log level

type Response

type Response struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

Response struct

func (*Response) JSON

func (r *Response) JSON(w http.ResponseWriter)

JSON response

type Router

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

Router is route slice and global middlewares

func NewRouter added in v1.1.0

func NewRouter() *Router

func (*Router) Add

func (rt *Router) Add(pattern, method string, callback func(gp *Goploy) *Response, middleware ...func(gp *Goploy) error) *Router

Add router pattern path callback where path should be handled

func (*Router) Middleware

func (rt *Router) Middleware(middleware func(gp *Goploy) error)

Middleware global Middleware handle function

func (*Router) Role

func (rt *Router) Role(role string) *Router

Role Add permission to the route

func (*Router) Roles

func (rt *Router) Roles(role []string) *Router

Roles Add much permission to the route

func (*Router) ServeHTTP

func (rt *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Router) Start

func (rt *Router) Start()

Start a router

func (*Router) White added in v1.1.0

func (rt *Router) White() *Router

White no need to check login

Jump to

Keyboard shortcuts

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