server

package
v1.0.1010 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigPath = filepath.Join(gfile.Pwd(), "manifest", "config", "config.yaml")
View Source
var DefaultConfig = Config{
	Server: ServiceConfig{
		Default: ServiceDefault{
			Address:           ":8080",
			LogPath:           "./log/",
			LogStdout:         true,
			ErrorStack:        true,
			ErrorLogEnabled:   true,
			ErrorLogPattern:   "error-{Ymd}.log",
			AccessLogEnable:   false,
			FileServerEnabled: true,
		},
	},
	OpenAPITitle:       "",
	OpenAPIDescription: "Api列表 包含各端接口信息 字段注释 枚举说明",
	OpenAPIUrl:         "https://panel.magicany.cc:8888/btpanel",
	OpenAPIName:        "",
	DoMain:             []string{"localhost", "127.0.0.1"},
	OpenAPIVersion:     "v1.0",
	Dns:                "root:123456@tcp(127.0.0.1:3306)/test",
	Logger: LoggerConfig{
		Path:              "./log/",
		File:              "access-{Ymd}.log",
		Level:             "all",
		TimeFormat:        "2006-01-02 15:04:05",
		CtxKeys:           []string{},
		Header:            true,
		Stdout:            true,
		RotateSize:        "1M",
		RotateBackupLimit: 10,
	},
}

Functions

func AuthAdmin

func AuthAdmin(r *ghttp.Request)

AuthAdmin 鉴权中间件,只有后端登录成功之后才能通过

func AuthBase

func AuthBase(r *ghttp.Request, name string)

AuthBase 鉴权中间件,只有前端或者后端登录成功之后才能通过

func AuthIndex

func AuthIndex(r *ghttp.Request)

AuthIndex 鉴权中间件,只有前端登录成功之后才能通过

func AuthLoginSession

func AuthLoginSession(ctx context.Context, sessionKey string)

func CORSMiddleware

func CORSMiddleware(r *ghttp.Request)

func CreateFileDir

func CreateFileDir() error

CreateFileDir 创建文件目录

func DefaultConfigInit

func DefaultConfigInit()

func DefaultSqliteConfigInit

func DefaultSqliteConfigInit(path string, autoTime []string, debug bool, prefix ...string)

DefaultSqliteConfigInit 创建默认的sqlite数据库配置 不会再生成配置文件 @param path sqlite数据库路径 @param autoTime 自动时间字段[]string{"create_time","update_time"} @param debug 数据库调试模式 @param prefix 表前缀可空

func LoginCountSession

func LoginCountSession(ctx context.Context, sessionKey string)

func LoginJson

func LoginJson(r *ghttp.Request, msg string, data ...interface{})

LoginJson 返回登录json数据

  • @param ctx 上下文
  • @param msg 返回信息
  • @param data 返回数据

func MiddlewareError

func MiddlewareError(r *ghttp.Request)

MiddlewareError 异常处理中间件

func NoLogin

func NoLogin(r *ghttp.Request)

NoLogin 未登录返回

func ResponseJson

func ResponseJson(ctx context.Context, data interface{})

ResponseJson 返回json数据

  • @param ctx 上下文
  • @param data 返回数据

func SetConfigAndRun

func SetConfigAndRun(s *ghttp.Server, address string)

SetConfigAndRun 设置配置并运行服务 @param s *ghttp.Server 服务实例 @param address string 监听地址

func Start

func Start(agent string, maxSessionTime time.Duration, isApi bool, maxBody ...int64) *ghttp.Server

Start 启动服务

  • @param agent string 浏览器标识
  • @param maxSessionTime time.Duration session最大时间
  • @param isApi bool 是否开启api
  • @param maxBody ...int64 最大上传文件大小 默认200M
  • @return *ghttp.Server 服务实例

Types

type ApiRes

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

func Error

func Error(ctx context.Context) *ApiRes

func Success

func Success(ctx context.Context) *ApiRes

func (*ApiRes) End

func (a *ApiRes) End()

func (*ApiRes) FileDownload

func (a *ApiRes) FileDownload(path, name string)

func (*ApiRes) FileSelect

func (a *ApiRes) FileSelect(path string)

func (*ApiRes) SetCode

func (a *ApiRes) SetCode(code int) *ApiRes

func (*ApiRes) SetData

func (a *ApiRes) SetData(data interface{}) *ApiRes

func (*ApiRes) SetMsg

func (a *ApiRes) SetMsg(msg string) *ApiRes

type Config

type Config struct {
	Server             ServiceConfig   `yaml:"server"`
	Database           *DatabaseConfig `yaml:"database"`
	SkipUrl            string          `yaml:"skipUrl"`
	OpenAPITitle       string          `yaml:"openAPITitle"`
	OpenAPIDescription string          `yaml:"openAPIDescription"`
	OpenAPIUrl         string          `yaml:"openAPIUrl"`
	OpenAPIName        string          `yaml:"openAPIName"`
	DoMain             []string        `yaml:"doMain"`
	OpenAPIVersion     string          `yaml:"openAPIVersion"`
	Logger             LoggerConfig    `yaml:"logger"`
	Dns                string          `yaml:"dns"`
}

type DatabaseConfig

type DatabaseConfig struct {
	Default DatabaseDefault `yaml:"default"`
}

type DatabaseDefault

type DatabaseDefault struct {
	Host      string `yaml:"host" json:"host"`
	Link      string `yaml:"link" dc:"数据库连接字符串" json:"link"`
	Port      string `yaml:"port" json:"port"`
	User      string `yaml:"user" json:"user"`
	Pass      string `yaml:"pass" json:"pass"`
	Name      string `yaml:"name" json:"name"`
	Type      string `yaml:"type" json:"type"`
	Timezone  string `yaml:"timezone" json:"timezone"`
	Debug     bool   `yaml:"debug" json:"debug"`
	Charset   string `yaml:"charset" json:"charset"`
	CreatedAt string `yaml:"createdAt" json:"createdAt"`
	UpdatedAt string `yaml:"updatedAt" json:"updatedAt"`
}

type Json

type Json struct {
	Code int    `json:"code" d:"1"`
	Data any    `json:"data"`
	Msg  string `json:"msg" d:"操作成功"`
}

type LoggerConfig

type LoggerConfig struct {
	Path                string   `yaml:"path" json:"path"`
	File                string   `yaml:"file" json:"file"`
	Level               string   `yaml:"level" json:"level"`
	TimeFormat          string   `yaml:"timeFormat" json:"timeFormat"`
	CtxKeys             []string `yaml:"ctxKeys" json:"ctxKeys"`
	Header              bool     `yaml:"header" json:"header"`
	Stdout              bool     `yaml:"stdout" json:"stdout"`
	RotateSize          string   `yaml:"rotateSize" json:"rotateSize"`
	RotateBackupLimit   int      `yaml:"rotateBackupLimit" json:"rotateBackupLimit"`
	StdoutColorDisabled bool     `yaml:"stdoutColorDisabled" json:"stdoutColorDisabled"`
	WriterColorEnable   bool     `yaml:"writerColorEnable" json:"writerColorEnable"`
}

type PageSize

type PageSize struct {
	CurrentPage int         `json:"currentPage"`
	Data        interface{} `json:"data"`
	LastPage    int         `json:"lastPage"`
	PerPage     int         `json:"per_page"`
	Total       int         `json:"total"`
}

func SetPage

func SetPage(page, limit, total int, data interface{}) *PageSize

SetPage 设置分页

  • @param page 当前页
  • @param limit 每页显示条数
  • @param total 总条数
  • @param data 返回数据
  • @return PageSize

type ServiceConfig

type ServiceConfig struct {
	Default ServiceDefault `yaml:"default"`
}

type ServiceDefault

type ServiceDefault struct {
	Address           string `yaml:"address"`
	LogPath           string `yaml:"logPath"`
	LogStdout         bool   `yaml:"logStdout"`
	ErrorStack        bool   `yaml:"errorStack"`
	ErrorLogEnabled   bool   `yaml:"errorLogEnabled"`
	ErrorLogPattern   string `yaml:"errorLogPattern"`
	AccessLogEnable   bool   `yaml:"accessLogEnable"`
	AccessLogPattern  string `yaml:"accessLogPattern"`
	FileServerEnabled bool   `yaml:"fileServerEnabled"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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