Documentation ¶
Index ¶
- Constants
- Variables
- func AddCron(spec string, cmd func()) error
- func AddErrorMap(errNo int64, errMsg string)
- func DispatchRoute(httpCtx *HTTPContext)
- func GetAppName() string
- func GetAppPath() string
- func GetEnv() string
- func GetErrorMap(errNo int64) string
- func GetHostName() string
- func GetPid() int
- func GetVersion() string
- func Handler(pattern string, handler ControllerInterface) (err error)
- func HandlerFunc(pattern string, h http.HandlerFunc)
- func HotDeploy(hotDeployConfig configs.HotDeployConfig)
- func IsDevEnv() bool
- func IsProdEnv() bool
- func IsTestEnv() bool
- func Router(w http.ResponseWriter, r *http.Request)
- func Run() (err error)
- func SetErrorMap(m map[int64]string)
- func StaticHandler(pattern string, dir string)
- func StaticStripHandler(pattern string, dir string)
- func StopCron()
- type Controller
- func (ctl *Controller) After(httpCtx *HTTPContext)
- func (ctl *Controller) Before(httpCtx *HTTPContext)
- func (ctl *Controller) Finish(httpCtx *HTTPContext)
- func (ctl *Controller) Init(httpCtx *HTTPContext)
- func (ctl *Controller) NotFound(httpCtx *HTTPContext)
- func (ctl *Controller) ServerError(httpCtx *HTTPContext)
- type ControllerInterface
- type HTTPContext
- func (httpCtx *HTTPContext) GetCookie(key string) (s string)
- func (httpCtx *HTTPContext) GetForm(key string) string
- func (httpCtx *HTTPContext) GetFormInt(key string) int
- func (httpCtx *HTTPContext) Log() *logger.Log
- func (httpCtx *HTTPContext) Output()
- func (httpCtx *HTTPContext) Redirect(url string)
- func (httpCtx *HTTPContext) Render()
- func (httpCtx *HTTPContext) ReturnFileContent(contentType, filename string, file interface{})
- func (httpCtx *HTTPContext) ReturnJSON()
- func (httpCtx *HTTPContext) SetCookie(key, value string)
- func (httpCtx *HTTPContext) SetDownloadMode(filename string)
- func (httpCtx *HTTPContext) StopRun()
- func (httpCtx *HTTPContext) ThrowCheck(errNo int64, i interface{})
Constants ¶
View Source
const ( DEV = "dev" TEST = "test" PROD = "prod" )
Variables ¶
View Source
var ( //VERSION 版本 VERSION string //ENVIRONMENT 环境 ENVIRONMENT string PID = os.Getpid() HOSTNAME, _ = os.Hostname() )
View Source
var ( APPPATH = GetAppPath() APPNAME = GetAppName() )
View Source
var (
Config configs.AllConfig
)
View Source
var ErrStopRun = errors.New("user stop run")
ErrStopRun ..
Functions ¶
func AddErrorMap ¶
func GetAppName ¶
func GetAppName() string
func GetAppPath ¶
func GetAppPath() string
func GetErrorMap ¶
func GetHostName ¶
func GetHostName() string
func GetVersion ¶
func GetVersion() string
func Handler ¶
func Handler(pattern string, handler ControllerInterface) (err error)
Handler 暂时只支持2段
func HandlerFunc ¶
func HandlerFunc(pattern string, h http.HandlerFunc)
HandlerFunc register HandleFunc
func HotDeploy ¶
func HotDeploy(hotDeployConfig configs.HotDeployConfig)
func SetErrorMap ¶
func StaticHandler ¶
StaticHandler ... 如pattern=css,dir=./static,则css在./static下
func StaticStripHandler ¶
StaticStripHandler ... 如pattern=css,dir=./static/css,则css就是./static/css
Types ¶
type Controller ¶
type Controller struct { }
Controller ..
func (*Controller) Finish ¶
func (ctl *Controller) Finish(httpCtx *HTTPContext)
Finish 请不要实现Finish方法
func (*Controller) ServerError ¶
func (ctl *Controller) ServerError(httpCtx *HTTPContext)
ServerError .. 不要手动调用,用于捕获未知错误,手动请用Throw 该方法不能使用StopRun,也不能panic,因为会被自动调用
type ControllerInterface ¶
type ControllerInterface interface { Init(*HTTPContext) Before(*HTTPContext) After(*HTTPContext) Finish(*HTTPContext) NotFound(*HTTPContext) ServerError(*HTTPContext) }
ControllerInterface .. init和finish必定会执行,而且不允许被修改 Before和After之间是业务逻辑,所有Before也是必定会执行 用户手动StopRun()后,中止业务逻辑,跳过After,继续Finish
type HTTPContext ¶
type HTTPContext struct { Ctx context.Context `json:"-"` Cancel context.CancelFunc `json:"-"` ResponseWriter http.ResponseWriter `json:"-"` Request *http.Request `json:"-"` Session *session.Session `json:"-"` Layout string `json:"-"` Controller string `json:"-"` Action string `json:"-"` Path string `json:"-"` IsZip bool `json:"-"` //404和500页面被自动更改content-type,导致压缩后有问题,暂时不压缩 IsError bool `json:"-"` //html文本 Template string `json:"-"` //模板文件 TemplateFile string `json:"-"` //主要用于模板渲染 Data map[string]interface{} `json:"-"` FuncMap map[string]interface{} `json:"-"` IsJSON bool `json:"-"` //返回的json是否包含Header HasHeader bool `json:"-"` //是否只返回Response.Results里的数据 IsOnlyResults bool `json:"-"` common.Response `json:"response"` Header interface{} `json:"header"` //如果是下载文件,不执行After和Finish IsCloseRender bool `json:"-"` // contains filtered or unexported fields }
HTTPContext .. 渲染模板的数据放Data Json里的数据放Response Layout的功能未实现 TODO
func (*HTTPContext) GetCookie ¶
func (httpCtx *HTTPContext) GetCookie(key string) (s string)
func (*HTTPContext) GetForm ¶
func (httpCtx *HTTPContext) GetForm(key string) string
GetForm 优先post和put,然后get
func (*HTTPContext) GetFormInt ¶
func (httpCtx *HTTPContext) GetFormInt(key string) int
GetFormInt 优先post和put,然后get,转为int
func (*HTTPContext) Log ¶
func (httpCtx *HTTPContext) Log() *logger.Log
func (*HTTPContext) ReturnFileContent ¶
func (httpCtx *HTTPContext) ReturnFileContent(contentType, filename string, file interface{})
ReturnFileContent 下载文件服务
func (*HTTPContext) SetCookie ¶
func (httpCtx *HTTPContext) SetCookie(key, value string)
func (*HTTPContext) SetDownloadMode ¶
func (httpCtx *HTTPContext) SetDownloadMode(filename string)
SetDownloadMode ..
func (*HTTPContext) ThrowCheck ¶
func (httpCtx *HTTPContext) ThrowCheck(errNo int64, i interface{})
ThrowCheck
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
grpc
|
|
client
支持连接https+grpc共享端口的版本,也支持非证书版 Usage: conn, err := client.NewClientConn("localhost:63333", "server.crt", "server.grpc.io", grpc.WithPerRPCCredentials(&rpc.X{Value: "abc", Key: "x"})) client := rpc.NewHelloServiceClient(conn)
|
支持连接https+grpc共享端口的版本,也支持非证书版 Usage: conn, err := client.NewClientConn("localhost:63333", "server.crt", "server.grpc.io", grpc.WithPerRPCCredentials(&rpc.X{Value: "abc", Key: "x"})) client := rpc.NewHelloServiceClient(conn) |
discovery/register
// register service cr := register.NewConsulRegister(fmt.Sprintf("%s:%d", host, consul_port), 15) cr.Register(discovery.RegisterInfo{ Host: host, Port: port, ServiceName: "HelloService", UpdateInterval: time.Second})
|
// register service cr := register.NewConsulRegister(fmt.Sprintf("%s:%d", host, consul_port), 15) cr.Register(discovery.RegisterInfo{ Host: host, Port: port, ServiceName: "HelloService", UpdateInterval: time.Second}) |
server
支持https+grpc的共享端口版,不需要ca证书 获取http+grpc,两个服务必须独立端口 Usage: 如果是grpc+https s, err := server.NewServer(hfw.Config.Server, opt...) RegisterHelloServiceServer(s, &HelloServiceImpl{auth: auth.NewAuthWithHTTPS("value")}) 如果是http+grpc s, err := server.NewServer(hfw.Config.Server, opt...) RegisterHelloServiceServer(s, &HelloServiceImpl{auth: auth.NewAuth("value")}) go server.StartServer(s, ":1234")
|
支持https+grpc的共享端口版,不需要ca证书 获取http+grpc,两个服务必须独立端口 Usage: 如果是grpc+https s, err := server.NewServer(hfw.Config.Server, opt...) RegisterHelloServiceServer(s, &HelloServiceImpl{auth: auth.NewAuthWithHTTPS("value")}) 如果是http+grpc s, err := server.NewServer(hfw.Config.Server, opt...) RegisterHelloServiceServer(s, &HelloServiceImpl{auth: auth.NewAuth("value")}) go server.StartServer(s, ":1234") |
kill -INT pid 终止 kill -TERM pid 重启
|
kill -INT pid 终止 kill -TERM pid 重启 |
信号处理 kill -INT pid 终止 kill -TERM pid 重启 需要调用Wg.Add() 需要监听Shutdown通道
|
信号处理 kill -INT pid 终止 kill -TERM pid 重启 需要调用Wg.Add() 需要监听Shutdown通道 |
Click to show internal directories.
Click to hide internal directories.