app

package
Version: v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2018 License: Apache-2.0 Imports: 19 Imported by: 1

Documentation

Overview

This package is a web framework that compatible with sdk http package. It also has a predefined 'standard' app engine server called GoEngine accessible through helper functions Handle, Server and so on.

Quick start:

import "github.com/mnhkahn/gogogo/app"
import "github.com/mnhkahn/gogogo/logger"

func Index(c *app.Context) error {
	c.WriteString("hello, world")
	return nil
}

app.Handle("/", &app.Got{Index})

l, err := net.Listen("tcp", ":"+port)
if err != nil {
	logger.Errorf("Listen: %v", err)
	return
}
app.Serve(l)

For more information, goto godoc https://godoc.org/github.com/mnhkahn/gogogo/app.

A example site: http://cyeam.com.

Package app

Example
// Package app_test

package main

import (
	"github.com/mnhkahn/gogogo/app"
	"github.com/mnhkahn/gogogo/logger"
	"net"
)

func Index(c *app.Context) error {
	c.WriteString("hello, world")
	return nil
}

func main() {
	app.Handle("/", &app.Got{Index})

	l, err := net.Listen("tcp", ":1031")
	if err != nil {
		logger.Errorf("Listen: %v", err)
		return
	}
	app.Serve(l)
}
Output:

Index

Examples

Constants

View Source
const DefaultLimit = 20

DefaultLimit ...

Variables

View Source
var (
	VERSION = "N/A"
	BRANCH  = "N/A"
	BUILD   = "N/A"
)

go build version, use build flags to assign value. -ldflags='-X "github.com/mnhkahn/gogogo/app.VERSION=$(VERSION)" -X "github.com/mnhkahn/gogogo/app.BRANCH=$(branch)" -X "github.com/mnhkahn/gogogo/app.BUILD=$(DATE)"'

View Source
var DefaultHandler = NewHandler()

DefaultHandler ...

View Source
var (
	ErrConfNotInit = errors.New("appconfig is not init, forgot to call InitAppConf()? ")
)
View Source
var GoEngine = NewEngine()

Default predefined engine

Functions

func AppInfo

func AppInfo()

AppInfo prints app info with git version, git branch, build date and go version.

func BasicAuthHandler added in v1.0.9

func BasicAuthHandler(handler http.Handler, user, pwd string) http.Handler

BasicAuthHandler ...

func DebugRouter

func DebugRouter(c *Context) error

DebugRouter is a handler to show all routers.

func DefaultString

func DefaultString(key, def string) string

DefaultString ...

func FreeContext

func FreeContext(c *Context)

FreeContext ...

func GetConfigAuth

func GetConfigAuth() (string, string, error)

GetConfigAuth ...

func GoAppHandler

func GoAppHandler(c *Context) error

GoAppHandler is a handler to show debug information.

func Handle

func Handle(pattern string, h http.Handler)

Handle ...

func InitAppConf

func InitAppConf() error

InitAppConf ...

func InitRouter

func InitRouter()

InitRouter ...

func Int

func Int(key string) int

Int ...

func LimitServe

func LimitServe(limit int)

LimitServe ...

func LogLevelHandler

func LogLevelHandler(c *Context) error

LogLevelHandler is a handler to set log level for StdLogger.

func Serve

func Serve(l net.Listener)

Serve ...

func ServeMux

func ServeMux(l net.Listener, handler http.Handler)

ServeMux ...

func SetRecoverFunc

func SetRecoverFunc(r func(w http.ResponseWriter, r *http.Request))

SetRecoverFunc ...

func SetTimeout

func SetTimeout(d time.Duration)

SetTimeout ...

func StatHandler added in v1.0.9

func StatHandler(c *Context) error

func String

func String(key string) string

String ...

func Strings

func Strings(key string) []string

Strings ...

Types

type Context

type Context struct {
	Params         url.Values
	ResponseWriter http.ResponseWriter
	Request        *http.Request
}

Context ...

func AllocContext

func AllocContext(rw http.ResponseWriter, req *http.Request) *Context

AllocContext ...

func NewContext

func NewContext(rw http.ResponseWriter, req *http.Request) *Context

NewContext ...

func (*Context) Debug

func (c *Context) Debug() bool

Debug ...

func (*Context) Error

func (c *Context) Error(msg string)

Error ...

func (*Context) GetBool

func (c *Context) GetBool(key string) (bool, error)

GetBool ...

func (*Context) GetInt

func (c *Context) GetInt(key string, def ...int) (int, error)

GetInt ...

func (*Context) GetInt64

func (c *Context) GetInt64(key string, def ...int64) (int64, error)

GetInt64 ...

func (*Context) GetString

func (c *Context) GetString(key string, def ...string) string

GetString ...

func (*Context) GetStrings

func (c *Context) GetStrings(key string) []string

GetStrings ...

func (*Context) GetUInt

func (c *Context) GetUInt(key string, def ...uint) (uint, error)

GetUInt ...

func (*Context) GetUInt32

func (c *Context) GetUInt32(key string, def ...uint32) (uint32, error)

GetUInt32 ...

func (*Context) GetUInt64

func (c *Context) GetUInt64(key string, def ...uint64) (uint64, error)

GetUInt64 ...

func (*Context) GetUInt8

func (c *Context) GetUInt8(key string, def ...uint8) (uint8, error)

GetUInt8 ...

func (*Context) HTML

func (c *Context) HTML(filenames []string, data interface{})

HTML ...

func (*Context) HTMLFunc

func (c *Context) HTMLFunc(filenames []string, data interface{}, funcs template.FuncMap)

HTMLFunc ...

func (*Context) JSON

func (c *Context) JSON(v interface{})

JSON ...

func (*Context) Query

func (c *Context) Query() url.Values

Query ...

func (*Context) Serve

func (c *Context) Serve(v interface{})

Serve ...

func (*Context) URL

func (c *Context) URL() string

URL ...

func (*Context) WriteBytes

func (c *Context) WriteBytes(raw []byte)

WriteBytes ...

func (*Context) WriteString

func (c *Context) WriteString(str string)

WriteString ...

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine ...

func NewEngine

func NewEngine() *Engine

NewEngine ...

func NewEngine2

func NewEngine2() *Engine

NewEngine2 ...

func (*Engine) Handle

func (e *Engine) Handle(pattern string, h http.Handler)

Handle ...

func (*Engine) Serve

func (e *Engine) Serve(l net.Listener)

Serve ...

func (*Engine) ServeMux

func (e *Engine) ServeMux(l net.Listener, handler http.Handler)

ServeMux ...

type Got

type Got struct {
	H func(c *Context) error
}

Got ...

func (Got) ServeHTTP

func (h Got) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP ...

type Handler

type Handler struct {
	TimeOut     time.Duration
	RecoverFunc func(w http.ResponseWriter, r *http.Request) `json:"-"`
	Stats       map[string]*Stat
	// contains filtered or unexported fields
}

Handler ...

func NewHandler added in v1.0.9

func NewHandler() *Handler

NewHandler ...

func (*Handler) Cost added in v1.0.9

func (h *Handler) Cost(u string, st time.Time)

type Stat added in v1.0.9

type Stat struct {
	Cnt     int64
	SumTime time.Duration
	AvgTime time.Duration
}

Directories

Path Synopsis
Package example
Package example
handler
func_to_handler
Package func_to_handler ...
Package func_to_handler ...

Jump to

Keyboard shortcuts

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