glweb

package module
v0.0.0-...-639d092 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2015 License: Apache-2.0 Imports: 39 Imported by: 0

README

glweb

a web framework for go with lua

Documentation

Overview

Package cors provides handlers to enable CORS support.

Package expvar provides a standardized interface to public variables, such as operation counters in servers. It exposes these variables via HTTP at /debug/vars in JSON format.

Operations to set or modify these public variables are atomic.

In addition to adding the HTTP handler, this package registers the following variables:

cmdline   os.Args
memstats  runtime.Memstats

The package is sometimes only imported for the side effect of registering its HTTP handler and the above variables. To use it this way, link this package into your program:

import _ "expvar"

Package pprof serves via its HTTP server runtime profiling data in the format expected by the pprof visualization tool. For more information about pprof, see http://code.google.com/p/google-perftools/.

The package is typically only imported for the side effect of registering its HTTP handlers. The handled paths all begin with /debug/pprof/.

To use pprof, link this package into your program:

import _ "net/http/pprof"

If your application is not already running an http server, you need to start one. Add "net/http" and "log" to your imports and the following code to your main function:

go func() {
	log.Println(http.ListenAndServe("localhost:6060", nil))
}()

Then use the pprof tool to look at the heap profile:

go tool pprof http://localhost:6060/debug/pprof/heap

Or to look at a 30-second CPU profile:

go tool pprof http://localhost:6060/debug/pprof/profile

Or to look at the goroutine blocking profile:

go tool pprof http://localhost:6060/debug/pprof/block

To view all available profiles, open http://localhost:6060/debug/pprof/ in your browser.

For a study of the facility in action, visit

http://blog.golang.org/2011/06/profiling-go-programs.html

Index

Constants

This section is empty.

Variables

View Source
var BasicRealm = "GLWEB API Authorization"

Functions

func Allow

func Allow(opts *Options) http.HandlerFunc

Allow enables CORS for requests those match the provided options.

func Cmdline

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

Cmdline responds with the running program's command line, with arguments separated by NUL bytes. The package initialization registers it as /debug/pprof/cmdline.

func Do

func Do(f func(KeyValue))

Do calls f for each exported variable. The global variable map is locked during the iteration, but existing entries may be concurrently updated.

func Index

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

Index responds with the pprof-formatted profile named by the request. For example, "/debug/pprof/heap" serves the "heap" profile. Index responds to a request for "/debug/pprof/" with an HTML page listing the available profiles.

func MD5

func MD5(value string) string

func Profile

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

Profile responds with the pprof-formatted cpu profile. The package initialization registers it as /debug/pprof/profile.

func Publish

func Publish(name string, v Var)

Publish declares a named exported variable. This should be called from a package's init function when it creates its Vars. If the name is already registered then this will log.Panic.

func Symbol

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

Symbol looks up the program counters listed in the request, responding with a table mapping program counters to function names. The package initialization registers it as /debug/pprof/symbol.

func WalkDir

func WalkDir(dirPth, suffix string) (files []string, err error)

Types

type DB

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

func (*DB) Close

func (this *DB) Close()

func (*DB) DB

func (this *DB) DB() *sql.DB

func (*DB) Exec

func (this *DB) Exec(sqlstr string, args ...interface{}) (int64, error)

修改和删除

func (*DB) FetchRow

func (this *DB) FetchRow(sqlstr string, args ...interface{}) (map[string]string, error)

取一行数据,注意这类取出来的结果都是string

func (*DB) FetchRows

func (this *DB) FetchRows(sqlstr string, args ...interface{}) ([]map[string]string, error)

取多行,<span style="font-family: Arial, Helvetica, sans-serif;">注意这类取出来的结果都是string </span>

func (*DB) Insert

func (this *DB) Insert(sqlstr string, args ...interface{}) (int64, error)

插入

func (*DB) Open

func (this *DB) Open(db_user, db_pwd, db_host, db_database string)

type Float

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

Float is a 64-bit float variable that satisfies the Var interface.

func NewFloat

func NewFloat(name string) *Float

func (*Float) Add

func (v *Float) Add(delta float64)

Add adds delta to v.

func (*Float) Set

func (v *Float) Set(value float64)

Set sets v to value.

func (*Float) String

func (v *Float) String() string

type Func

type Func func() interface{}

Func implements Var by calling the function and formatting the returned value using JSON.

func (Func) String

func (f Func) String() string

type GLWeb

type GLWeb struct {
	filemonitor.FileMonitorAdaptor
	// contains filtered or unexported fields
}

func NewGLWeb

func NewGLWeb(glspath string) *GLWeb

func (*GLWeb) DB

func (self *GLWeb) DB(db_user, db_pwd, db_host, db_database string)

func (*GLWeb) FileCreate

func (self *GLWeb) FileCreate(file *filemonitor.FileEntry)

func (*GLWeb) FileDelete

func (self *GLWeb) FileDelete(file *filemonitor.FileEntry)

func (*GLWeb) FileModify

func (self *GLWeb) FileModify(file *filemonitor.FileEntry)

func (*GLWeb) Run

func (self *GLWeb) Run(hp string)

func (*GLWeb) ServeHTTP

func (self *GLWeb) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Int

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

Int is a 64-bit integer variable that satisfies the Var interface.

func NewInt

func NewInt(name string) *Int

func (*Int) Add

func (v *Int) Add(delta int64)

func (*Int) Set

func (v *Int) Set(value int64)

func (*Int) String

func (v *Int) String() string

type KeyValue

type KeyValue struct {
	Key   string
	Value Var
}

KeyValue represents a single entry in a Map.

type Map

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

Map is a string-to-Var map variable that satisfies the Var interface.

func NewMap

func NewMap(name string) *Map

func (*Map) Add

func (v *Map) Add(key string, delta int64)

func (*Map) AddFloat

func (v *Map) AddFloat(key string, delta float64)

AddFloat adds delta to the *Float value stored under the given map key.

func (*Map) Do

func (v *Map) Do(f func(KeyValue))

Do calls f for each entry in the map. The map is locked during the iteration, but existing entries may be concurrently updated.

func (*Map) Get

func (v *Map) Get(key string) Var

func (*Map) Init

func (v *Map) Init() *Map

func (*Map) Set

func (v *Map) Set(key string, av Var)

func (*Map) String

func (v *Map) String() string

type Options

type Options struct {
	// If set, all origins are allowed.
	AllowAllOrigins bool
	// A list of allowed origins. Wild cards and FQDNs are supported.
	AllowOrigins []string
	// If set, allows to share auth credentials such as cookies.
	AllowCredentials bool
	// A list of allowed HTTP methods.
	AllowMethods []string
	// A list of allowed HTTP headers.
	AllowHeaders []string
	// A list of exposed HTTP headers.
	ExposeHeaders []string
	// Max age of the CORS headers.
	MaxAge time.Duration
}

Options represents Access Control options.

func (*Options) Header

func (o *Options) Header(origin string) (headers map[string]string)

Header converts options into CORS headers.

func (*Options) IsOriginAllowed

func (o *Options) IsOriginAllowed(origin string) (allowed bool)

IsOriginAllowed looks up if the origin matches one of the patterns generated from Options.AllowOrigins patterns.

func (*Options) PreflightHeader

func (o *Options) PreflightHeader(origin, rMethod, rHeaders string) (headers map[string]string)

PreflightHeader converts options into CORS headers for a preflight response.

type RouteMatch

type RouteMatch int
const (
	NoMatch RouteMatch = iota
	StarMatch
	OverloadMatch
	ExactMatch
)

func (RouteMatch) BetterThan

func (r RouteMatch) BetterThan(o RouteMatch) bool

Higher number = better match

type String

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

String is a string variable, and satisfies the Var interface.

func NewString

func NewString(name string) *String

func (*String) Set

func (v *String) Set(value string)

func (*String) String

func (v *String) String() string

type Task

type Task struct {
	Name    string
	Method  string
	Action  string
	Version string
	Fn      string
	Info    string
}

type Tasks

type Tasks struct {
	Name string
	Task []*Task
}

type Var

type Var interface {
	String() string
}

Var is an abstract type for all exported variables.

func Get

func Get(name string) Var

Get retrieves a named exported variable.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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