cc

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2023 License: MIT Imports: 25 Imported by: 0

README

cc

A Go Web Frame

Documentation

Index

Constants

View Source
const DEFAULT_BUILD_NAME = "main"
View Source
const DEFAULT_CONFIG_PATH = "application.yaml"

DEFAULT_CONFIG_PATH 默认配置文件地址

Variables

View Source
var (
	LogInfo  = infoLogger.Println
	LogInfof = infoLogger.Printf
	LogWarn  = warnLogger.Println
	LogWarnf = warnLogger.Printf
	LogErr   = errLogger.Println
	LogErrf  = errLogger.Printf
)

Functions

func Code

func Code(code int) *responseCode

Code 构造状态码响应

func Data

func Data(code int, v []byte) *responseData

Data 构造字节流响应

func Html

func Html(code int, v []byte) *responseHtml

Html 构造网页响应

func JWTToken

func JWTToken(payload map[string]any, secret []byte) (string, error)

JwtToken JWT加密获取token

func Json

func Json(code int, v any) *responseJson

Json 构造 json 响应

func ParseJWT

func ParseJWT(token string, secret []byte) (map[string]any, error)

ParseJWT 解析JWT

func Redirect

func Redirect(code int, v string) *responseRedirect

Redirect 构造重定向响应

func String

func String(code int, format string, v ...any) *responseString

String 构造字符串响应

Types

type AppConfig

type AppConfig struct {
	Main         string `yaml:"main"`
	Port         int    `yaml:"port"`
	ReadTimeout  int    `yaml:"read-timeout"`
	WriteTimeout int    `yaml:"write-timeout"`
	IdleTimeout  int    `yaml:"idle-timeout"`
	Production   bool   `yaml:"production"`
	Database     struct {
		Source       string `yaml:"source"`
		MaxOpenConns int    `yaml:"max-open-conns"`
		MaxIdleConns int    `yaml:"max-idle-conns"`
	} `yaml:"database"`
	Watch struct {
		Includes []string `yaml:"includes"`
		Excludes []string `yaml:"excludes"`
		Debounce int64    `yaml:"debounce"`
	} `yaml:"watch"`
}

AppConfig 项目配置

func NewAppConfig

func NewAppConfig() *AppConfig

NewAppConfig 构造带默认参数的项目配置

func (*AppConfig) ParseContent

func (config *AppConfig) ParseContent(content []byte) error

ParseContent 解析配置内容

func (*AppConfig) ParseFile

func (config *AppConfig) ParseFile(path string) error

ParseFile 解析配置文件

type CAppConfig

type CAppConfig []byte // 项目配置

type CTLSCertFile

type CTLSCertFile string // TLS证书

type CTLSKeyFile

type CTLSKeyFile string // TLS密钥

type Context

type Context struct {
	Req    *http.Request
	Writer http.ResponseWriter
	Method string
	Path   string
	Params map[string]string
	// contains filtered or unexported fields
}

Context 上下文

func NewContext

func NewContext(w http.ResponseWriter, r *http.Request, session *orm.Session) *Context

NewContext 新建上下文

func (*Context) Body

func (ctx *Context) Body() []byte

Body 获取请求体

func (*Context) Cookie

func (ctx *Context) Cookie(key string) *http.Cookie

Cookie 获取请求Cookie

func (*Context) File

func (ctx *Context) File(key string) (multipart.File, *multipart.FileHeader, error)

File 获取上传文件 TODO 多文件上传,文件关闭

func (*Context) Header

func (ctx *Context) Header(key string) string

Header 获取请求头

func (*Context) Param

func (ctx *Context) Param(key string) string

Param 获取路由参数

func (*Context) PostForm

func (ctx *Context) PostForm(key string) string

PostForm 获取表单参数

func (*Context) Query

func (ctx *Context) Query(key string) string

Query 获取请求参数

func (*Context) Session

func (ctx *Context) Session() *orm.Session

func (*Context) SetCookie

func (ctx *Context) SetCookie(c *http.Cookie)

SetCookie 设置响应Cookie

func (*Context) SetHeader

func (ctx *Context) SetHeader(key, value string)

SetHeader 设置响应头

func (*Context) SetMaxFileSize

func (ctx *Context) SetMaxFileSize(v int64) error

SetMaxFileSize 设置允许最大内存及文件大小,单位字节

type Engine

type Engine struct {
	*RouteGroup
	// contains filtered or unexported fields
}

Engine Web引擎

func New

func New() *Engine

New 构造Engine

func (*Engine) DrawRoute

func (engine *Engine) DrawRoute()

DrawRoute 输出路由

func (*Engine) Run

func (engine *Engine) Run(options ...any)

Run 启动 Web Server

func (*Engine) ServeHTTP

func (engine *Engine) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP 实现 http.Handler 接口

type Handler

type Handler func(ctx *Context) Response

Handler 处理器

func (Handler) Invoke

func (handler Handler) Invoke(ctx *Context) Response

Invoke 实现 IHandler 接口

type IHandler

type IHandler interface {
	Invoke(ctx *Context) Response
}

IHandler 处理器接口

type J

type J map[string]any

J json结构

type Response

type Response interface {
	Invoke(ctx *Context)
}

Response 响应接口

type RouteGroup

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

RouteGroup 分组路由

func (*RouteGroup) After

func (group *RouteGroup) After(v ...func(*Context) Response)

After 添加后置处理拦截器

func (*RouteGroup) Before

func (group *RouteGroup) Before(v ...func(*Context) Response)

Before 添加拦截器

func (*RouteGroup) Get

func (group *RouteGroup) Get(pattern string, handler func(*Context) Response)

Get 添加 GET 请求

func (*RouteGroup) Group

func (group *RouteGroup) Group(prefix string) *RouteGroup

Group 创建新的路由分组

func (*RouteGroup) Post

func (group *RouteGroup) Post(pattern string, handler func(*Context) Response)

Post 添加 POST 请求

Directories

Path Synopsis
bind

Jump to

Keyboard shortcuts

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