TeaGo

package module
v0.0.0-...-31a7bc8 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 26 Imported by: 118

README

TeaGo - Go语言快速开发框架

|------------|       |---------|       |----------|
|  request   |   ->  | router  |   ->  | actions  |
|------------|       |---------|       |----------|
                                            json
                                         templates
                                         databases

定义不带参数的Action

actions/default/hello/index.go

package hello

import "github.com/iwind/TeaGo/actions"

type IndexAction actions.Action

func (this *IndexAction) Run()  {
	this.WriteString("Hello")
}

定义带参数的Action

actions/default/hello/index.go

package hello

import "github.com/iwind/TeaGo/actions"

type IndexAction actions.Action

func (this *IndexAction) Run(params struct {
	Name string
	Age  int
}) {
	this.WriteFormat("Name:%s, Age:%d",
		params.Name,
		params.Age)
}

注册Action

package MyProject

import (
	"github.com/iwind/TeaGo"
	"github.com/iwind/MyProject/actions/default/hello/index"
)

func Start() {
	var server = TeaGo.NewServer()
	
	// 注册路由
	server.Get("/hello", new(hello.IndexAction))
	
	// 启动服务
	server.Start("0.0.0.0:8000")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BeforeStart

func BeforeStart(fn func(server *Server))

BeforeStart 在服务启动之前执行一个函数

func BeforeStop

func BeforeStop(fn func(server *Server))

BeforeStop 在服务停止之前执行一个函数

Types

type DefaultLogWriter

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

func (*DefaultLogWriter) Close

func (this *DefaultLogWriter) Close()

func (*DefaultLogWriter) Init

func (this *DefaultLogWriter) Init()

func (*DefaultLogWriter) Print

func (this *DefaultLogWriter) Print(t time.Time, response *responseWriter, request *http.Request)

func (*DefaultLogWriter) Write

func (this *DefaultLogWriter) Write(logMessage string)

type FileLogWriter

type FileLogWriter struct {
	File string
	// contains filtered or unexported fields
}

func (*FileLogWriter) Close

func (this *FileLogWriter) Close()

func (*FileLogWriter) Init

func (this *FileLogWriter) Init()

func (*FileLogWriter) Print

func (this *FileLogWriter) Print(t time.Time, response *responseWriter, request *http.Request)

func (*FileLogWriter) Write

func (this *FileLogWriter) Write(logMessage string)

type LogWriter

type LogWriter interface {
	Init()
	Print(t time.Time, response *responseWriter, request *http.Request)
	Write(logMessage string)
	Close()
}

type Server

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

Server Web服务

func NewServer

func NewServer(singleInstance ...bool) *Server

NewServer 构建一个新的Server

func (*Server) AccessLog

func (this *Server) AccessLog(bool bool) *Server

AccessLog 设置是否打印访问日志

func (*Server) All

func (this *Server) All(path string, actionPtr interface{}) *Server

All 将所有方法映射到路由

func (*Server) Any

func (this *Server) Any(methods []string, path string, actionPtr interface{}) *Server

Any 设置一组方法路由映射

func (*Server) ConnState

func (this *Server) ConnState(connState func(conn net.Conn, state http.ConnState)) *Server

ConnState 连接状态

func (*Server) Connect

func (this *Server) Connect(path string, actionPtr interface{}) *Server

Connect 设置 CONNECT 方法路由映射

func (*Server) Data

func (this *Server) Data(name string, value interface{}) *Server

Data 设置变量

func (*Server) Delete

func (this *Server) Delete(path string, actionPtr interface{}) *Server

Delete 设置 DELETE 方法路由映射

func (*Server) EndAll

func (this *Server) EndAll() *Server

EndAll 结束所有定义

func (*Server) EndData

func (this *Server) EndData() *Server

EndData 结束设置变量

func (*Server) EndHelpers

func (this *Server) EndHelpers() *Server

EndHelpers 结束助手定义

func (*Server) EndModule

func (this *Server) EndModule() *Server

EndModule 设置模块定义结束

func (*Server) EndPrefix

func (this *Server) EndPrefix() *Server

EndPrefix 结束前缀定义

func (*Server) Get

func (this *Server) Get(path string, actionPtr interface{}) *Server

Get 设置 GET 方法路由映射

func (*Server) GetPost

func (this *Server) GetPost(path string, actionPtr interface{}) *Server

GetPost 设置 GET 和 POST 方法路由映射

func (*Server) Head

func (this *Server) Head(path string, actionPtr interface{}) *Server

Head 设置 HEAD 方法路由映射

func (*Server) Helper

func (this *Server) Helper(helper interface{}) *Server

Helper 定义助手

func (*Server) InternalErrorLogger

func (this *Server) InternalErrorLogger(errorLogger *log.Logger) *Server

func (*Server) LogWriter

func (this *Server) LogWriter(logWriter LogWriter) *Server

LogWriter 设置日志writer

func (*Server) Module

func (this *Server) Module(module string) *Server

Module 设置模块定义开始

func (*Server) Options

func (this *Server) Options(path string, actionPtr interface{}) *Server

Options 设置 OPTIONS 方法路由映射

func (*Server) Post

func (this *Server) Post(path string, actionPtr interface{}) *Server

Post 设置 POST 方法路由映射

func (*Server) Prefix

func (this *Server) Prefix(prefix string) *Server

Prefix 设置URL前缀

func (*Server) Purge

func (this *Server) Purge(path string, actionPtr interface{}) *Server

Purge 设置 PURGE 方法路由映射

func (*Server) Put

func (this *Server) Put(path string, actionPtr interface{}) *Server

Put 设置 PUT 方法路由映射

func (*Server) ReadHeaderTimeout

func (this *Server) ReadHeaderTimeout(timeout time.Duration) *Server

func (*Server) ReadTimeout

func (this *Server) ReadTimeout(timeout time.Duration) *Server

func (*Server) Session

func (this *Server) Session(sessionManager interface{}, cookieName string) *Server

Session 设置SESSION管理器

func (*Server) Start

func (this *Server) Start()

Start 启动服务

func (*Server) StartOn

func (this *Server) StartOn(address string)

StartOn 在某个地址上启动服务

func (*Server) Static

func (this *Server) Static(prefix string, dir string) *Server

Static 添加静态目录

func (*Server) Stop

func (this *Server) Stop()

func (*Server) Trace

func (this *Server) Trace(path string, actionPtr interface{}) *Server

Trace 设置 TRACE 方法路由映射

type ServerConfig

type ServerConfig struct {
	Http struct {
		On              bool     `yaml:"on" json:"on"`
		Listen          []string `yaml:"listen" json:"listen"`                   // 监听地址,带端口
		RedirectToHTTPS bool     `yaml:"redirectToHTTPS" json:"redirectToHTTPS"` // 自动跳转到HTTPS
	} `yaml:"http" json:"http"`
	Https struct {
		On     bool     `yaml:"on" json:"on"`
		Listen []string `yaml:"listen" json:"listen"`
		Cert   string   `yaml:"cert" json:"cert"`
		Key    string   `yaml:"key" json:"key"`
	} `yaml:"https" json:"https"`
	Env     string `yaml:"env" json:"env"`         // 环境,dev、test或prod
	Charset string `yaml:"charset" json:"charset"` // 字符集
	Upload  struct {
		MaxSize string `yaml:"maxSize" json:"maxSize"` // 允许上传的最大尺寸
		// contains filtered or unexported fields
	} `yaml:"upload" json:"upload"` // 上传配置
	Errors map[string]interface{} `yaml:"errors" json:"errors"` // 错误配置
}

ServerConfig 服务配置

func (*ServerConfig) Load

func (this *ServerConfig) Load()

func (*ServerConfig) MaxSize

func (this *ServerConfig) MaxSize() float64

type ServerRoutePattern

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

ServerRoutePattern 路由配置

type ServerStaticDir

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

ServerStaticDir 静态资源目录

Directories

Path Synopsis
dbs
atom
Package atom provides integer codes (also known as atoms) for a fixed set of frequently occurring HTML strings: tag names and attribute keys such as "p" and "id".
Package atom provides integer codes (also known as atoms) for a fixed set of frequently occurring HTML strings: tag names and attribute keys such as "p" and "id".
utils

Jump to

Keyboard shortcuts

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