coderg

package module
v0.0.0-...-f74961c Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2015 License: GPL-3.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

项目已经移动到:https://github.com/idcsource


CoderG

这是一个用Go语言开发的极简Web和B/S框架。


主要特点

  • 以“单元”(Unit)的概念对实现某一功能模块的一组控制器的管理;

  • 通过“门口”(UnitDoor)文件对“单元”内控制器进行路由管理;

  • 使用“节点”(Node)和“节点树”(NodeTree)来组织“单元”和路由信息;

  • 通过“节点树”实现直接的全站无限级分类和自动化的路由表生成;

  • 支持HTTP和HTTPS。


局限

  • 因为本框架的主要目标是放在“单元”和“节点”上,所以并没有针对GET和POST等多方式请求做任何处理,而且也没有的URL的请求返回做过多处理。

  • 因为CoderG开发者本人只在Go下用过PostgreSQL,所以目前CoderG关于数据库连接方面也只为PostgreSQL准备(必须连接),而且没有使用任何ORM,也没有model层。

  • CoderG的功能很单纯,目标很明确,所以不要指望它大而全,什么功能都有。


依赖

CoderG依赖两个第三方包:

  • github.com/msbranco/goconfig,用来对所有的配置文件进行处理;

  • github.com/lib/pq,PostgreSQL的数据库驱动。


项目网站

目前项目网站还只有一个临时的访问地址:CoderG。在这里你可以查看文档并提问。


使用

  • 使用 go get "github.com/firemeditation/coderg" 进行安装;

  • 在自己的站点项目中用 import "github.com/firemeditation/coderg" 引用。


其他

  • webconfig-example.cfg 文件为示例用的网站配置文件,其中标出“必需”的项目请保证一定要包含在你自己的配置文件中,否则CoderG无法运行。

  • CoderG使用 GNU GPL v3 许可证授权,不喜勿入。

Documentation

Index

Constants

This section is empty.

Variables

View Source
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		# 数据库名

func DirMustEnd

func DirMustEnd(dir string) string

DirMustEnd 路径必须以斜线结尾

func GetSha1

func GetSha1(data string) string

func PathMustBegin

func PathMustBegin(path string) string

PathMustBegin 路径必须以斜线开始

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) EditorIn

func (ip *InputProcessor) EditorIn(text string, must bool, min, max int) (textc string, err int)

* EditorIn * 处理编辑器的输入,除了字数检测外,主要是过滤script标签

func (*InputProcessor) EditorRe

func (ip *InputProcessor) EditorRe(text string) string

* EditorRe * 处理编辑器的重新编辑

func (*InputProcessor) Email

func (ip *InputProcessor) Email(text string, must bool, min, max int) (textc string, err int)

* Email * 查看格式是不是邮箱地址

func (*InputProcessor) Enum

func (ip *InputProcessor) Enum(text string, must bool, enum []string) (textc string, err int)

* Enum * 枚举,判断提供的字符串是否出现在字符串切片里

func (*InputProcessor) Float

func (ip *InputProcessor) Float(text string, must bool, min, max float64) (num float64, err int)

* Float * 输入是否为浮点 *

func (*InputProcessor) Int

func (ip *InputProcessor) Int(text string, must bool, min, max int64) (num int64, err int)

* Int * 输入是否为整数 *

func (*InputProcessor) Mark

func (ip *InputProcessor) Mark(text string, must bool, min, max int) (textc string, err int)

* Mark * 处理作为标记的的字符串,只能由字母数字和连字符组成

func (*InputProcessor) Regular

func (ip *InputProcessor) Regular(text string, must bool, rg string) (textc string, err int)

* Regular * 正则判断,提供一个正则表达,如果匹配则返回字符串

func (*InputProcessor) Text

func (ip *InputProcessor) Text(text string, must bool, min, max int) (textc string, err int)

* Text * 处理简单文本输入,替换可能引起注入的字符、判断长度等

func (*InputProcessor) TextareaOut

func (ip *InputProcessor) TextareaOut(text string, thetype bool) string

* TextareaOut * 处理文本域的输出,主要就是对换行符进行处理,将\r\n之类的转换成<p>或<br> * thetype为true则转成<p>,type为false则转为<br> *

func (*InputProcessor) Url

func (ip *InputProcessor) Url(text string, must bool, min, max int) (textc string, err int)

* Url * 处理连接,主要是如果没有协议的话,就加上http://

type NodeTree

type NodeTree struct {
	Mark            string               //用来做路由的,也就是未来显示在连接上的地址
	Config          *goconfig.ConfigFile //配置文件
	IfChildren      bool                 //是否有下层
	IfDoor          bool                 //是否为入口
	ControllorValue reflect.Value        //控制器的反射值
	Children        map[string]*NodeTree //下层的信息,map的键为Mark
}

func NewNodeTree

func NewNodeTree(c ControllorInterface) *NodeTree

新建节点树,并输入跟节点的控制器

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 NewRouterPath

func NewRouterPath(service *ServiceStruct) *RouterPath

新建路由

func (*RouterPath) AddDynamic

func (r *RouterPath) AddDynamic(url string, c ControllorInterface)

添加动态路由

func (*RouterPath) AddIndexRoute

func (r *RouterPath) AddIndexRoute(c ControllorInterface)

添加IndexRoute

func (*RouterPath) AddNotFind

func (r *RouterPath) AddNotFind(c ControllorInterface)

添加404路由

func (*RouterPath) AddStatic

func (r *RouterPath) AddStatic(url, path string) (err error)

添加静态路由

func (*RouterPath) Init

func (r *RouterPath) Init(service *ServiceStruct)

新建路由

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

type TemplateCache map[string]*template.Template

此数据类型在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)

type UnitRouterDynamic

type UnitRouterDynamic struct {
	Url             string
	ControllorValue reflect.Value
}

Jump to

Keyboard shortcuts

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