mod

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

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

Go to latest
Published: Aug 17, 2014 License: BSD-2-Clause Imports: 7 Imported by: 0

README

mod

HTTP Helper modules.

mod 处于开发期, 正式项目慎用.

风格

签名接口:

/**
Interface for module
签名接口, 表示采用 mod 的接口风格.
*/
type Interface interface {
    GitHubTypepressMod()
}

所有的 module 都包含两个方法:

签名 GitHubTypepressMod()
执行 ServeHTTP

ServeHTTP 参数风格:

/**
参数:
    最后两个参数类型是 `http.ResponseWriter`, `*http.Request`.
    之前的参数无限制.
返回:
    true  表示请求已完成, 应该停止响应
    false 表示请求未完成, 可以继续响应.
*/
ServeHTTP(v1 Type, vN TypeN, http.ResponseWriter, *http.Request) bool

LICENSE

Copyright (c) 2014 The TypePress Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtIndex

func ExtIndex(exts string, ext string) int

* ExtIndex 辅助函数, 模仿 strings.Index 风格. 返回 ext 在 exts 中第一个完整匹配的位置. 参数:

exts 举例 ".jpg.html", 不要有空格
ext  举例 ".js"

返回:

-1 表示匹配失败, ext 为空也返回 -1.
其它值表示匹配到的位置.

func Redirect

func Redirect(root http.Dir,
	rw http.ResponseWriter, req *http.Request) bool

* Redirect 遵守 http 1.1 规范对目录进行 301 重定向.

依据:

URL.Path 以 "/index.html" 结尾.
URL.Path 是目录, 没有以 "/" 结尾.

参数:

root 指定文档根路径

Types

type Dir

func GzipPreInExts

func GzipPreInExts(exts string) Dir

* GzipPre 发送静态预压缩文件, root 路径由调用者传递.

依据:

Request.Method 为 GET/HEAD
Request.Header 含 "Accept-Encoding" 支持 "gzip".
URL.Path 有扩展名.
exts 非空, 扩展名在 exts 内.
对应的 ".gz" 预压缩文件存在.

参数:

exts 指定文件扩展名, 如果为空, 表示尝试所有文件.

返回:

文件被发送返回 true, 否则返回 false

注意:

确保相应文件类型已注册 mime Content-Type.

func List

func List(n int) Dir

* List 使用简洁风格列表目录, root 路径由调用者传递.

参数:

n    限制目录列表的个数, n <= 0 表示不限制.

返回:

true  目录被列表
false 目录未被列表

func StaticInExts

func StaticInExts(exts string) Dir

* StaticInExts 发送静态文件, root 路径由调用者传递.

依据:

Request.Method 为 GET/HEAD
URL.Path 有扩展名.
exts 非空, 扩展名在 exts 内.
文件存在.

参数:

exts 指定文件扩展名, 如果为空, 表示尝试所有文件.

返回:

文件被发送返回 true, 否则返回 false

func (Dir) GitHubTypepressMod

func (h Dir) GitHubTypepressMod()

func (Dir) ServeHTTP

func (h Dir) ServeHTTP(dir http.Dir,
	rw http.ResponseWriter, req *http.Request) bool

type Finish

type Finish func(http.ResponseWriter, *http.Request) bool

func AllowExtIn

func AllowExtIn(exts string) Finish

* AllowExtIn, URL.Path 扩展名不在 exts 内, 403 完结.

func AllowPrefix

func AllowPrefix(prefix string) Finish

* AllowPrefix, URL.Path 不含有指定 prefix, 403 完结.

func DenyExtIn

func DenyExtIn(exts string) Finish

* DenyExtIn, URL.Path 扩展名在 exts 内, 403 完结.

func DenyPrefix

func DenyPrefix(prefix string) Finish

* DenyPrefix, URL.Path 含有指定 prefix, 403 完结.

func DirList

func DirList(root http.Dir, n int) Finish

* DirList 调用 List 使用简洁风格列表目录.

参数:

root 指定文档根路径
n    限制目录列表的个数, n <= 0 表示不限制.

返回:

true  目录被列表
false 目录未被列表

func DirRedirect

func DirRedirect(root http.Dir) Finish

* DirRedirect 调用 Redirect 对目录进行 301 重定向.

参数:

root 指定文档根路径

func GzipPre

func GzipPre(root http.Dir, exts string) Finish

* GzipPre 调用 GzipPreInExts 发送静态预压缩文件. 参数:

root 指定文档根路径
exts 指定文件扩展名, 如果为空, 表示尝试所有文件.

返回:

文件被发送返回 true, 否则返回 false

func SetCacheControl

func SetCacheControl(cc map[string]string) Finish

* SetCacheControl 以扩展名设置 Cache-Control 头 参数:

cc 举例
	map[string]string{
		".jpg": "max-age=31536000",
	}

返回:

总是 false

func Static

func Static(root http.Dir, exts string) Finish

* Static 调用 StaticInExts 发送静态文件. 参数:

root 指定文档根路径
exts 指定文件扩展名, 如果为空, 表示尝试所有文件.

返回:

文件被发送返回 true, 否则返回 false

func (Finish) GitHubTypepressMod

func (h Finish) GitHubTypepressMod()

func (Finish) ServeHTTP

func (h Finish) ServeHTTP(
	rw http.ResponseWriter, req *http.Request) bool

type Interface

type Interface interface {
	// 占位签名, 表示采用 mod 的接口风格.
	GitHubTypepressMod()
}

* Interface for mod

type String

type String func(string, http.ResponseWriter, *http.Request) bool

func (String) GitHubTypepressMod

func (h String) GitHubTypepressMod()

func (String) ServeHTTP

func (h String) ServeHTTP(v string,
	rw http.ResponseWriter, req *http.Request) bool

type Uint

type Uint func(uint, http.ResponseWriter, *http.Request) bool

func (Uint) GitHubTypepressMod

func (h Uint) GitHubTypepressMod()

func (Uint) ServeHTTP

func (h Uint) ServeHTTP(v uint,
	rw http.ResponseWriter, req *http.Request) bool

Jump to

Keyboard shortcuts

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