Documentation ¶
Index ¶
- Variables
- func DatabasePrepare(conf *goconfig.ConfigFile) *sql.DB
- func DirMustEnd(dir string) string
- func GetSha1(data string) string
- func PathMustBegin(path string) string
- type Controllor
- type ControllorInterface
- type InputProcessor
- func (ip *InputProcessor) EditorIn(text string, must bool, min, max int) (textc string, err int)
- func (ip *InputProcessor) EditorRe(text string) string
- func (ip *InputProcessor) Email(text string, must bool, min, max int) (textc string, err int)
- func (ip *InputProcessor) Enum(text string, must bool, enum []string) (textc string, err int)
- func (ip *InputProcessor) Float(text string, must bool, min, max float64) (num float64, err int)
- func (ip *InputProcessor) Int(text string, must bool, min, max int64) (num int64, err int)
- func (ip *InputProcessor) Mark(text string, must bool, min, max int) (textc string, err int)
- func (ip *InputProcessor) Regular(text string, must bool, rg string) (textc string, err int)
- func (ip *InputProcessor) Text(text string, must bool, min, max int) (textc string, err int)
- func (ip *InputProcessor) TextareaOut(text string, thetype bool) string
- func (ip *InputProcessor) Url(text string, must bool, min, max int) (textc string, err int)
- type NodeTree
- type RouterDynamic
- type RouterPath
- func (r *RouterPath) AddDynamic(url string, c ControllorInterface)
- func (r *RouterPath) AddIndexRoute(c ControllorInterface)
- func (r *RouterPath) AddNotFind(c ControllorInterface)
- func (r *RouterPath) AddStatic(url, path string) (err error)
- func (r *RouterPath) Init(service *ServiceStruct)
- func (r *RouterPath) Router(httpw http.ResponseWriter, httpr *http.Request, rt Runtime, s *ServiceStruct)
- func (r *RouterPath) ServeHTTP(httpw http.ResponseWriter, httpr *http.Request)
- type Runtime
- type ServiceStruct
- type TemplateCache
- type TemplateConfig
- type UnitDoorInterface
- type UnitRouter
- type UnitRouterDynamic
Constants ¶
This section is empty.
Variables ¶
var ServiceGo sync.WaitGroup
ServiceGo 为唯一的全局变量,为了协调各服务
Functions ¶
func DatabasePrepare ¶
func DatabasePrepare(conf *goconfig.ConfigFile) *sql.DB
DatabasePrepare 数据库准备函数 此函数根据传入配置文件中关于数据库连接的信息进行配置,使用Golang自己的数据库接口,返回*sql.DB类型的数据库连接 此函数目前只处理针对PostgreSQL数据库的连接 具体查看配置文件终的配置参数为: [database]
server # 数据库服务器的地址 port # 数据库服务器的端口号 user # 数据库访问用户名 passwd # 数据库访问用户的密码 dbname # 数据库名
Types ¶
type Controllor ¶
type Controllor struct { Runtime Runtime Service *ServiceStruct W http.ResponseWriter R *http.Request }
func (*Controllor) Exec ¶
func (c *Controllor) Exec()
func (*Controllor) Init ¶
func (c *Controllor) Init(w http.ResponseWriter, r *http.Request, service *ServiceStruct, rt Runtime)
Init 函数负责对控制器进行初始化 根据Runtime中的NowRoutePath,使用strings.Split函数根据“/”分割并作为Runtime中的UrlRequest(已清除可能的为空的字符串)
type ControllorInterface ¶
type ControllorInterface interface { Init(w http.ResponseWriter, r *http.Request, service *ServiceStruct, rt Runtime) Exec() }
ControllorInterface 此为控制器接口的定义
type InputProcessor ¶
type InputProcessor struct {
// contains filtered or unexported fields
}
func NewInputProcessor ¶
func NewInputProcessor() (ip *InputProcessor)
func (*InputProcessor) EditorRe ¶
func (ip *InputProcessor) EditorRe(text string) string
* EditorRe * 处理编辑器的重新编辑
func (*InputProcessor) TextareaOut ¶
func (ip *InputProcessor) TextareaOut(text string, thetype bool) string
* TextareaOut * 处理文本域的输出,主要就是对换行符进行处理,将\r\n之类的转换成<p>或<br> * thetype为true则转成<p>,type为false则转为<br> *
type NodeTree ¶
type NodeTree struct { Mark string //用来做路由的,也就是未来显示在连接上的地址 Config *goconfig.ConfigFile //配置文件 IfChildren bool //是否有下层 IfDoor bool //是否为入口 ControllorValue reflect.Value //控制器的反射值 Children map[string]*NodeTree //下层的信息,map的键为Mark }
func (*NodeTree) AddNode ¶
func (nt *NodeTree) AddNode(mark, conf string, c ControllorInterface) (*NodeTree, string)
添加Children,返回Children的子节点书
func (*NodeTree) AddUnit ¶
func (nt *NodeTree) AddUnit(mark, conf string, d UnitDoorInterface) (*NodeTree, string)
func (*NodeTree) Router ¶
func (nt *NodeTree) Router(s *ServiceStruct)
生成路由,直接加入Service里的MainRouter中
type RouterDynamic ¶
type RouterDynamic struct { Regexp *regexp.Regexp Equal string ControllorValue reflect.Value IfConfig bool Config map[string]*goconfig.ConfigFile RealNode string }
动态路由信息
type RouterPath ¶
type RouterPath struct { IndexRoute reflect.Value IndexRouteIsSet bool Static map[string]*regexp.Regexp Dynamic []RouterDynamic NotFind reflect.Value NotFindIsSet bool Service *ServiceStruct }
总路由信息
func (*RouterPath) AddDynamic ¶
func (r *RouterPath) AddDynamic(url string, c ControllorInterface)
添加动态路由
func (*RouterPath) AddIndexRoute ¶
func (r *RouterPath) AddIndexRoute(c ControllorInterface)
添加IndexRoute
func (*RouterPath) Router ¶
func (r *RouterPath) Router(httpw http.ResponseWriter, httpr *http.Request, rt Runtime, s *ServiceStruct)
路由
func (*RouterPath) ServeHTTP ¶
func (r *RouterPath) ServeHTTP(httpw http.ResponseWriter, httpr *http.Request)
HTTP的路由
type Runtime ¶
type Runtime struct { AllRoutePath string //整个的RoutePath,也就是除域名外的完整路径 NowRoutePath string //AllRoutePath经过层级路由之后剩余的部分,通常是提供的Request参数 RealNode string //当前节点的树名,如/node1/node2,如果没有使用节点则此处为空 ConfigTree map[string]*goconfig.ConfigFile //节点的配置文件树,从当前节点开始到最上层父节点,以节点名称为键名 MyConfig *goconfig.ConfigFile //当前节点的配置文件,从ConfigTree中获取,如当前节点没有配置文件,则去寻找父节点,直到载入站点的配置文件 UrlRequest []string //Url请求的整理,具体行文见Controllor }
Runtime 运行时数据 此运行时数据由CoderG中的Router或Controllor生成
type ServiceStruct ¶
type ServiceStruct struct { GlobalRelativePath string //本地路径 Grp string //GlobalRelativePath WebConfig *goconfig.ConfigFile //配置文件 MainRouter *RouterPath //总路由 //TemplateConfig TemplateConfig //模板配置缓存 NodeTree *NodeTree //节点树 Template TemplateCache //模板准备缓存,这个没有自动的,只有手动的准备和注册 Database *sql.DB //数据库连接 }
func ServicePrepare ¶
func ServicePrepare(configfile string) (Service *ServiceStruct)
ServicePrepare 此函数为“服务”的准备,需要一个配置文件,并返回ServiceStruct
func (*ServiceStruct) Start ¶
func (s *ServiceStruct) Start()
func (*ServiceStruct) Wait ¶
func (s *ServiceStruct) Wait()
type TemplateCache ¶
此数据类型在Service中初始化,提供手动在运行前缓存模板的功能
type TemplateConfig ¶
type TemplateConfig map[string]*goconfig.ConfigFile
func (TemplateConfig) AllCache ¶
func (tc TemplateConfig) AllCache(thePath string)
AllCache 这个函数提供了缓存thePath路径下(遍历子路经)所有.cfg文件的功能 数据库的保存格式为map[string]*goconfig.ConfigFile 其中string为配置文件名不包含.cfg的部分,如果在子路经下则包含子路经,例如:abc/def
func (TemplateConfig) ReadAndAdd ¶
func (tc TemplateConfig) ReadAndAdd(dir, path string)
type UnitDoorInterface ¶
type UnitDoorInterface interface {
Router() (router *UnitRouter)
}
type UnitRouter ¶
type UnitRouter struct {
Info []UnitRouterDynamic
}
func NewUnitRouter ¶
func NewUnitRouter() (router *UnitRouter)
func (*UnitRouter) Add ¶
func (r *UnitRouter) Add(url string, c ControllorInterface)