goio

package
v1.2.93 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2024 License: Apache-2.0 Imports: 31 Imported by: 0

README

go.io

framework interfaces and configurations for libraries

package main

import (
	"github.com/gif-gif/go.io/goio"
	"github.com/gif-gif/go.io/goio/test/router"
)

func main() {
	startSever()
}

func startSever() {
	goio.Init(goio.DEVELOPMENT)
	s := goio.NewServer(
		goio.ServerNameOption("serverName"),
		goio.EnvOption(goio.Env),
		//goio.EnableEncryptionOption(),
		goio.PProfEnableOption(false),
		goio.NoLogPathsOption("/captcha/get"),
	)

	// 路由
	router.Routes(s.Group("/"))
	// 启动
	s.Run(":1000")
}
curl --location --request POST 'http://127.0.0.1:1000/health' \
--header 'User-Agent: Apifox/1.0.0 (https://apifox.com)'

Documentation

Index

Constants

View Source
const ERROR_DATABASE int64 = 555
View Source
const ERROR_FORBIDDEN int64 = 403
View Source
const ERROR_INVALID int64 = -1
View Source
const ERROR_NOTFOUND int64 = 404
View Source
const ERROR_PARAMS int64 = 700
View Source
const ERROR_REDIS int64 = 556
View Source
const ERROR_REQUEST int64 = 400

client

View Source
const ERROR_SERVER int64 = 500

server

View Source
const ERROR_UNAUTHORIZED int64 = 401
View Source
const SUCCESS_REQUEST = 0

Variables

View Source
var (
	Version     string
	VersionFlag = flag.Bool("v", false, "version")

	HelpFlag = flag.Bool("h", false, "help")
)
View Source
var (
	UnknownStatus = 0
	StatusValid   = 1
	StatusInValid = 2
)

Functions

func ClientIP added in v1.2.24

func ClientIP(c *gin.Context) string

客户端IP

func CreateToken added in v1.0.17

func CreateToken(appId string, openid int64) (tokenStr string, err error)

func FlagInit added in v1.0.13

func FlagInit()

func GrpcContext added in v1.2.24

func GrpcContext(c *gin.Context) context.Context

func Handler added in v1.2.24

func Handler(controller iController) gin.HandlerFunc

定义控制器调用实现

func Init added in v1.0.14

func Init(env Environment)

func LoadJsonConfig added in v1.2.34

func LoadJsonConfig(jsonFile string, conf interface{}) (err error)

func LoadYamlConfig added in v1.2.34

func LoadYamlConfig(yamlFile string, conf interface{}) (err error)

func RequestBody added in v1.2.24

func RequestBody(c *gin.Context) interface{}

请求数据

func RequestId added in v1.2.24

func RequestId(c *gin.Context) string

唯一ID

func ValidationMessage added in v1.2.24

func ValidationMessage(err error, messages map[string]string) string

Types

type Config added in v1.2.52

type Config struct {
	Env Environment `yaml:"env"`

	Server struct {
		Addr string `yaml:"addr"`
		Name string `yaml:"name"`
	} `yaml:"server"`

	Prometheus  prometheusx.Config  `yaml:"prometheus"`
	MongoDB     gomongo.Config      `yaml:"mongodb"`
	Mysql       gogorm.Config       `yaml:"mysql"`
	Postgres    gogorm.Config       `yaml:"postgres"`
	Sqlite      gogorm.Config       `yaml:"sqlite"`
	Clickhouse1 gogorm.Config       `yaml:"clickhouse1"`
	Redis       goredis.Config      `yaml:"redis"`
	Kafka       gokafka.Config      `yaml:"kafka"`
	Clickhouse  goclickhouse.Config `yaml:"clickhouse"`
	Es          goes.Config         `yaml:"es"`

	Etcd goetcd.Config `yaml:"etcd"`

	FeiShu string `yaml:"feishu"`
}

type Encryption added in v1.2.24

type Encryption struct {
	Key    string
	Secret string
}

func (*Encryption) Decode added in v1.2.24

func (enc *Encryption) Decode(str string) (b []byte, err error)

func (*Encryption) Encode added in v1.2.24

func (enc *Encryption) Encode(b []byte) (str string, err error)

type Environment added in v1.0.15

type Environment string
const (
	PRODUCTION  Environment = "pro"
	PRE         Environment = "pre"
	RT          Environment = "rt"
	TEST        Environment = "test"
	DEVELOPMENT Environment = "dev"
)

库运行模式 dev|test|rt|pre|pro go-zero

var Env Environment //string `json:",default=pro,options=dev|test|rt|pre|pro"`

当前运行环境

func (Environment) String added in v1.0.15

func (env Environment) String() string

func (Environment) Tag added in v1.0.15

func (env Environment) Tag() string

type LocalUpload added in v1.2.24

type LocalUpload struct {
}

func (LocalUpload) Upload added in v1.2.24

func (lu LocalUpload) Upload(c *gin.Context, uploadDir string) *Response

type Option added in v1.2.24

type Option interface {
	// contains filtered or unexported methods
}

func CorsHeaderOption added in v1.2.24

func CorsHeaderOption(corsHeaders ...string) Option

跨域

func EnableEncryptionOption added in v1.2.24

func EnableEncryptionOption(encryptKey, encryptSecret string, excludeUris ...string) Option

启用加密传输

func EnvOption added in v1.2.24

func EnvOption(env Environment) Option

运行环境

func NoAccessPathsOption added in v1.2.24

func NoAccessPathsOption(noAccessPaths ...string) Option

禁止访问的path

func NoLogPathsOption added in v1.2.24

func NoLogPathsOption(noLogPaths ...string) Option

不记录日志的path

func PProfEnableOption added in v1.2.24

func PProfEnableOption(pprofEnable bool) Option

开启分析

func ServerNameOption added in v1.2.24

func ServerNameOption(serverName string) Option

服务名称

type Response

type Response struct {
	Code    int32         `json:"code"`
	Message string        `json:"message"`
	Data    interface{}   `json:"data"`
	Errors  []interface{} `json:"-"`
}

func Error added in v1.2.24

func Error(code int32, message string, v ...interface{}) *Response

func ErrorWithValidate added in v1.2.24

func ErrorWithValidate(err error, messages map[string]string) *Response

func Success added in v1.2.24

func Success(data interface{}) *Response

func (*Response) Copy added in v1.2.24

func (rsp *Response) Copy() *Response

func (*Response) String added in v1.2.24

func (rsp *Response) String() string

type Server added in v1.2.24

type Server struct {
	*gin.Engine
}

自己定义web服务

func NewServer added in v1.2.24

func NewServer(opt ...Option) *Server

func (*Server) Run added in v1.2.24

func (s *Server) Run(addr string)

启动服务

type Token added in v1.0.17

type Token struct {
	AppId     string `json:"app_id"`
	OpenId    int64  `json:"data"`
	NonceStr  string `json:"nonce"`
	Timestamp int64  `json:"ts"`
}

func ParseToken added in v1.0.17

func ParseToken(tokenStr, appId string) (token *Token, err error)

func (*Token) Bytes added in v1.0.17

func (t *Token) Bytes() []byte

func (*Token) String added in v1.0.17

func (t *Token) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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