Documentation
¶
Overview ¶
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- func Env(key string) string
- func Envs(i interface{}, mode ...string)
- func InitLogger(rw io.Writer)
- func RegisterFilter(filter Filter, values ...string) bool
- func RegisterURI(uri URI, cangoName ...string) bool
- func RegisterURIWithPrefix(prefix string, uri URI, cangoName ...string) bool
- func SessionGet(r *http.Request, key string, value interface{})
- func SessionPut(r *http.Request, rw http.ResponseWriter, key string, value interface{}, ...)
- func SetError(code int, fn func(w http.ResponseWriter, r *http.Request))
- func SetGorillaSessionStore(store sessions.Store)
- func Version() string
- func WriteJSON(w http.ResponseWriter, obj interface{}) error
- type Addr
- type Can
- func (can *Can) FallbackHandler(handler http.Handler) *Can
- func (can *Can) Filter(f Filter, uris ...URI) *Can
- func (can *Can) GinRoute(eg *gin.Engine)
- func (can *Can) Mode(runMode string) *Can
- func (can *Can) RegTplFunc(name string, fn interface{}) *Can
- func (can *Can) Route(uris ...URI) *Can
- func (can *Can) RouteFunc(fns ...interface{}) *Can
- func (can *Can) RouteFuncWithPrefix(prefix string, fns ...interface{}) *Can
- func (can *Can) RouteWithPrefix(prefix string, uris ...URI) *Can
- func (can *Can) Run(as ...interface{}) error
- func (can *Can) ServeHTTP(rw http.ResponseWriter, r *http.Request)
- func (can *Can) SetJsonWriter(rth responseTypeHandler) *Can
- func (p *Can) Shutdown() *Can
- func (can *Can) ToGins() []*GinHandler
- type Caster
- type Constructor
- type Content
- type ContentWithCode
- type DeleteMethod
- type DoNothing
- type Filter
- type FilterType
- type GetMethod
- type GinHandler
- type HeadMethod
- type IniConfig
- type Invoker
- type JSON
- type ModelView
- type OptionsMethod
- type Opts
- type PatchMethod
- type PostMethod
- type PutMethod
- type Redirect
- type RedirectWithCode
- type StaticFile
- type TraceMethod
- type URI
- type WebRequest
- func (wr *WebRequest) IsDelete() bool
- func (wr *WebRequest) IsGet() bool
- func (wr *WebRequest) IsHead() bool
- func (wr *WebRequest) IsOptions() bool
- func (wr *WebRequest) IsPatch() bool
- func (wr *WebRequest) IsPost() bool
- func (wr *WebRequest) IsPut() bool
- func (wr *WebRequest) IsTrace() bool
- func (wr *WebRequest) SessionGet(key string, value interface{})
- func (wr *WebRequest) SessionPut(key string, value interface{}, opts ...*sessions.Options)
- func (wr *WebRequest) SetCookie(ck *http.Cookie)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterFilter ¶
func RegisterURI ¶
RegisterURI todo with can app Name ??? RegisterURI 在定义struct的时候引入,也这是非常推荐的方法
func RegisterURIWithPrefix ¶
RegisterURIWithPrefix 在定义struct的时候引入,同时使用prefix做为路由前缀,也这是非常推荐的方法
func SessionGet ¶
func SessionPut ¶
func SetError ¶
func SetError(code int, fn func(w http.ResponseWriter, r *http.Request))
SetError can define http status code with specific method
func SetGorillaSessionStore ¶
func Version ¶
func Version() string
Version returns the cango tree's version string. It is either the commit hash and date at the time of the build or, when possible, a release tag like "v1.0.0-rc1".
func WriteJSON ¶ added in v0.0.2
func WriteJSON(w http.ResponseWriter, obj interface{}) error
WriteJSON marshals the given interface object and writes it with custom ContentType.
Types ¶
type Can ¶
type Can struct {
// contains filtered or unexported fields
}
func (*Can) RegTplFunc ¶
RegTplFunc 用name注册fn函数,方便在渲染模板时使用
func (*Can) RouteFuncWithPrefix ¶
RouteFuncWithPrefix 带有前缀的方法路由,可以传入多个方法(便于版本、分组等管理)
func (*Can) RouteWithPrefix ¶
RouteWithPrefix todo route with suffix and simplify Route路由结构体上所有的可导出方法,并使用路由前缀
func (*Can) SetJsonWriter ¶
SetJsonWriter will set a json writer
func (*Can) ToGins ¶
func (can *Can) ToGins() []*GinHandler
type Constructor ¶
type Constructor interface {
Construct(request *WebRequest)
}
Constructor is the interface that wraps the Construct method.
Construct 可以从*http.Request中进行初始化变量
type Content ¶
type Content struct {
String string
}
func (Content) WithCode ¶
func (c Content) WithCode(code int) *ContentWithCode
type ContentWithCode ¶
type Filter ¶
type Filter interface { // PreHandle is used to perform operations before sending the request to the controller. // This method should return true to continue the request serve. // If this method returns false,the request will stop. // If this method returns cango-return type(Redirect/ModelView...),the request will response with the type PreHandle(request *WebRequest) interface{} // PostHandle is used to perform operations before sending the response to the client. // This method should return true. PostHandle(request *WebRequest) interface{} }
todo 为什么filter 不使用和URI一样的方式进行注册
type FilterType ¶
type GinHandler ¶
type IniConfig ¶
type IniConfig struct {
// contains filtered or unexported fields
}
func NewIniConfig ¶
type Invoker ¶
Invoker 实际执行请求的函数 kind用来表示是通过struct来注册的还是只是通过函数来注册的 0 invokeBySelf --- 通过函数 1 invokeByReceiver --- 通过struct
type JSON ¶ added in v0.0.2
type JSON struct {
Data interface{}
}
func (JSON) Render ¶ added in v0.0.2
func (r JSON) Render(w http.ResponseWriter) (err error)
Render (JSON) writes data with custom ContentType.
func (JSON) WriteContentType ¶ added in v0.0.2
func (r JSON) WriteContentType(w http.ResponseWriter)
WriteContentType (JSON) writes JSON ContentType.
type Opts ¶
type Opts struct { // 监听的主机 Host string // 监听的端口 Port int // 模板文件文件夹,相对程序运行路径 TplDir string // 静态文件文件夹,相对程序运行路径 StaticDir string // 模板文件后续名,默认为 .tpl 和 .html TplSuffix []string // 是否调试页面,true 表示每次都重新加载模板 DebugTpl bool // 日志文件位置,绝对路径 CanlogPath string // gorilla cookie store 的key CookieSessionKey string // gorilla cookie store 加密使用的key CookieSessionSecure string // TLS 文件 CertFile, KeyFile string }
Opts 程序启动的配置参数
type Redirect ¶
type Redirect struct {
Url string
}
func (Redirect) WithCode ¶
func (r Redirect) WithCode(code int) *RedirectWithCode
type RedirectWithCode ¶
type StaticFile ¶
type StaticFile struct {
Path string
}
type URI ¶
type URI interface {
Request() *WebRequest
}
type WebRequest ¶
type WebRequest struct { http.ResponseWriter *http.Request }
func (*WebRequest) IsDelete ¶
func (wr *WebRequest) IsDelete() bool
IsDelete check the request method is http.MethodDelete
func (*WebRequest) IsGet ¶
func (wr *WebRequest) IsGet() bool
IsGet check the request method is http.MethodGet
func (*WebRequest) IsHead ¶
func (wr *WebRequest) IsHead() bool
IsHead check the request method is http.MethodHead
func (*WebRequest) IsOptions ¶
func (wr *WebRequest) IsOptions() bool
IsOptions check the request method is http.MethodOptions
func (*WebRequest) IsPatch ¶
func (wr *WebRequest) IsPatch() bool
IsPatch check the request method is http.MethodPatch
func (*WebRequest) IsPost ¶
func (wr *WebRequest) IsPost() bool
IsPost check the request method is http.MethodPost
func (*WebRequest) IsPut ¶
func (wr *WebRequest) IsPut() bool
IsPut check the request method is http.MethodPut
func (*WebRequest) IsTrace ¶
func (wr *WebRequest) IsTrace() bool
IsTrace check the request method is http.MethodTrace
func (*WebRequest) SessionGet ¶
func (wr *WebRequest) SessionGet(key string, value interface{})
func (*WebRequest) SessionPut ¶
func (wr *WebRequest) SessionPut(key string, value interface{}, opts ...*sessions.Options)
func (*WebRequest) SetCookie ¶
func (wr *WebRequest) SetCookie(ck *http.Cookie)
SetCookie adds a Set-Cookie header to the provided ResponseWriter's headers. The provided cookie must have a valid Name. Invalid cookies may be silently dropped.