本文整理汇总了Golang中github.com/paulbellamy/mango.Env类的典型用法代码示例。如果您正苦于以下问题:Golang Env类的具体用法?Golang Env怎么用?Golang Env使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Env类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: editEvent
func editEvent(env mango.Env) (mango.Status, mango.Headers, mango.Body) {
db := env["AssetTracker.db"].(*sql.DB)
req := env.Request()
switch req.Method {
case "GET":
break
case "POST":
event := models.Event{}
req.ParseForm()
decoder := schema.NewDecoder()
err := decoder.Decode(&event, req.Form)
if err != nil {
log.Println(err)
}
log.Printf("Received Event %#v", event)
_, err = crud.Insert(db, "events", "event_id", event)
if err != nil {
log.Println(err)
return internalServerError()
}
return 201, mango.Headers{}, mango.Body("Event saved")
}
return 404, mango.Headers{}, mango.Body("404")
}
开发者ID:cwc,项目名称:asset-tracker,代码行数:31,代码来源:route_edit_event.go
示例2: Hello
func Hello(env mango.Env) (mango.Status, mango.Headers, mango.Body) {
r := env.Request()
env.Logger().Println("Got a ", r.Method, " request for ", r.RequestURI)
name := r.URL.Query().Get("name")
body := fmt.Sprintf("Hello %s!", name)
return 200, mango.Headers{}, mango.Body(body)
}
开发者ID:hfeeki,项目名称:bingo,代码行数:7,代码来源:hello.go
示例3: Logger
func Logger(env mango.Env, app mango.App) (status mango.Status, headers mango.Headers, body mango.Body) {
startTime := time.Now()
r := env.Request()
log.Printf("Started %s \"%s\" for %s at %s\n", r.Method, r.RequestURI, r.RemoteAddr, startTime.String())
status, headers, body = app(env)
execution := time.Now().Sub(startTime) / time.Millisecond
log.Printf("Completed %d in %dms\n\n", status, execution)
return
}
开发者ID:sunfmin,项目名称:mangolog,代码行数:9,代码来源:log.go
示例4: Authenticated
func Authenticated(env mango.Env, app mango.App) (status mango.Status, headers mango.Headers, body mango.Body) {
if env.Request().FormValue("Password") != "nopassword" {
body = "Not authorized."
status = 403
return
}
status, headers, body = app(env)
return
}
开发者ID:sunfmin,项目名称:streamango,代码行数:9,代码来源:whole_test.go
示例5: Logger
func Logger(env mango.Env, app mango.App) (status mango.Status, headers mango.Headers, body mango.Body) {
startTime := time.Now()
r := env.Request()
if err := r.ParseMultipartForm(32 << 20); err != nil {
panic(err)
}
log.Printf("Started %s \"%s\" for %s at %s\n", r.Method, r.RequestURI, r.RemoteAddr, startTime.String())
log.Printf("Form %v; Accept: %+v \n", r.Form, r.Header["Accept"])
status, headers, body = app(env)
execution := time.Now().Sub(startTime) / time.Millisecond
log.Printf("Completed %d in %dms\n\n", status, execution)
return
}
开发者ID:kobeld,项目名称:mangolog,代码行数:16,代码来源:log.go
示例6: submitHandler
// Handler function to accept the submitted form post with the SSN
func submitHandler(env mango.Env) (mango.Status, mango.Headers, mango.Body) {
log.Println("Submit GetUserData Request")
cr := &myStartup.GetUserDataRequest{YourInputValue: env.Request().FormValue("YourInputValue")}
resp, err := submitGetUserDataRequest(cr)
if err != nil {
log.Println(err.String())
}
log.Println(resp)
buffer := &bytes.Buffer{}
respTmpl.Execute(buffer, map[string]interface{}{
"resp": resp,
})
return 200, mango.Headers{}, mango.Body(buffer.String())
}
开发者ID:andradeandrey,项目名称:skynet,代码行数:18,代码来源:mangoInitiator.go
示例7: Producer
func Producer(env mango.Env) (status mango.Status, headers mango.Headers, body mango.Body) {
env.Logger().Println("Got a", env.Request().Method, "request for", env.Request().RequestURI)
if strings.HasPrefix(env.Request().RequestURI, "/producer.json") {
status = 200
headers = mango.Headers{"Content-Type": []string{"application/json;charset=utf-8"}}
json_data := make(map[string]interface{})
json_data["test"] = "NO"
json_data["date"] = "2013-08-16T15:31:20+10:00"
json_data["count"] = 1000
json_string, _ := json.Marshal(json_data)
body = mango.Body(json_string)
} else {
status = 404
body = mango.Body("Invalid path")
}
return
}
开发者ID:uglyog,项目名称:example_pact_with_go,代码行数:20,代码来源:producer.go
示例8: editAsset
func editAsset(env mango.Env) (mango.Status, mango.Headers, mango.Body) {
db := env["AssetTracker.db"].(*sql.DB)
tmpl := env["AssetTracker.tpl"].(*template.Template)
req := env.Request()
switch req.Method {
case "GET":
var asset models.Asset
uriParams := env["Routing.matches"].([]string)
if len(uriParams) > 1 {
id, err := strconv.ParseInt(uriParams[1], 10, 64)
if err != nil {
log.Println(err)
return defaultHandler(env)
}
asset, err = models.GetAssetById(db, id)
if err != nil {
log.Println(err)
return internalServerError()
}
} else {
asset = models.Asset{}
}
args := map[string]interface{}{
"Title": "Edit Asset",
"Asset": asset,
}
var buf bytes.Buffer
if err := tmpl.ExecuteTemplate(&buf, "editAsset.tpl", args); err != nil {
log.Println(err)
return internalServerError()
}
return 200, mango.Headers{}, mango.Body(buf.String())
case "POST":
asset := models.Asset{}
req.ParseForm()
decoder := schema.NewDecoder()
err := decoder.Decode(&asset, req.Form)
if err != nil {
log.Println(err)
}
log.Printf("Received Asset %#v", asset)
// Update or create the new asset
if asset.Id > 0 {
err = crud.Update(db, "assets", "asset_id", asset)
} else {
_, err = crud.Insert(db, "assets", "asset_id", asset)
}
if err != nil {
log.Println(err)
return internalServerError()
}
return 201, mango.Headers{}, mango.Body("Asset saved")
}
return 404, mango.Headers{}, mango.Body("404")
}
开发者ID:cwc,项目名称:asset-tracker,代码行数:68,代码来源:route_edit_asset.go
注:本文中的github.com/paulbellamy/mango.Env类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论