rootpath

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

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

Go to latest
Published: Apr 14, 2014 License: BSD-2-Clause Imports: 8 Imported by: 0

README

rootpath

Martini middleware/handler for easily set domain root path

Documentation

Overview

根据域名匹配相关目录

Index

Constants

View Source
const (
	// flags of category for RootPath.Flag
	FStatic   = 1 << iota // category name is _static
	FContent              // category name is _content
	FTemplate             // category name is _template

	FAll = FStatic | FContent | FTemplate

	// flags of target rootpath for RootPath.Flag
	FDontJoinCategoryName = 0x40000000
	FDontJoinDomain       = 0x80000000
)

Variables

This section is empty.

Functions

func Handler

func Handler(statusCode int, root ...RootPath) martini.Handler

*

返回多域名路径设置 handler. 依据 roots 匹配 Request.Host.
匹配成功设置相应路径, 无匹配时依据 statusCode 进行操作.
statusCode:
  - 0 无操作
  - 其他 WriteHeader(statusCode)

Types

type RootPath

type RootPath struct {
	Pattern      string
	Domain       string
	Root         string
	Flag         int
	CategoryName []string
}

*

  RootPath 使用简单的规则来确定域名根目录

  Pattern: 域名匹配规则, "?" 规则多了一次目录检查, 是否 join example.com 部分由 FDontJoinDomain 标记决定

	- ""  完全匹配             example.com , Root/[example.com]/[category]
	- "." 泛域名相同目录 [foo.]example.com , Root/[example.com]/[category]
	- "*" 泛域名独立目录 [foo.]example.com , Root/[foo.][example.com]/[category]
	- "?" 泛域名泛目录   [foo.]example.com , Root/[foo.][example.com]/[category] 或 Root/[example.com]/[category]

  Domain: 域名
  Root:   基本目录
  Flag:   根目录的分类标记, 参见 FStatic 等常量, 0 特指所有类型
  CategoryName: 自定义 category 的名字, 顺序对应 static,content,template. 缺省使用 "_static","_content","_template"

func (RootPath) Match

func (r RootPath) Match(host string) (bool, string)

*

匹配 host, 要求 host 不包含 port 部分. 返回:
是否匹配成功, 子域名部分(尾部不包括".")

Jump to

Keyboard shortcuts

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