middlewares

package
v0.0.0-...-d31700d Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CORS

type CORS struct {
	SetHeader func(http.Header)
	// contains filtered or unexported fields
}

crosss origin resource share

func NewCORS

func NewCORS(allow func(origin string, c *goa.Context) bool) CORS

func (CORS) Check

func (cors CORS) Check(c *goa.Context)

type Logger

type Logger struct {
	Logger            *loggerPkg.Logger
	PanicHandler      func(*goa.Context)
	ShouldLogReqBody  func(*goa.Context) bool
	ShouldLogRespBody func(*goa.Context) bool
}
Example
ts, buf := startTestServer()
defer ts.Close()
if _, err := http.Post(
	ts.URL+"?a=b&c=d", "application/json", strings.NewReader("[0,1,2]"),
); err != nil {
	log.Panic(err)
}
printLog(buf)
Output:

{"code":"ok","message":"good"}
 31
agent: "Go-http-client/1.1"
host: "127.0.0.1:3000"
ip: "127.0.0.1"
level: "info"
method: "POST"
path: "/"
rawQuery: "a=b&c=d"
refer: ""
reqBody: "[0,1,2]"
reqBodySize: 7
requestId: ""
respBody: "{\"code\":\"ok\",\"message\":\"good\"}\n"
respBodySize: 31
session: "session-data"
status: 200
Example (Debug)
ts, buf := startTestServer()
defer ts.Close()
if _, err := http.Post(
	ts.URL+"?a=b&c=d&_debug", "application/json", strings.NewReader("[0,1,2]"),
); err != nil {
	log.Panic(err)
}
printLog(buf)
Output:

{"code":"ok","message":"good"}
 31
agent: "Go-http-client/1.1"
host: "127.0.0.1:3000"
ip: "127.0.0.1"
level: "info"
method: "POST"
path: "/"
rawQuery: "a=b&c=d&_debug"
refer: ""
reqBody: "[0,1,2]"
reqBodySize: 7
requestId: ""
respBody: "{\"code\":\"ok\",\"message\":\"good\"}\n"
respBodySize: 31
session: "session-data"
status: 200
Example (Panic)
ts, buf := startTestServer()
defer ts.Close()
if _, err := http.Get(ts.URL + "/panic?_debug"); err != nil {
	log.Panic(err)
}
printLog(buf)
Output:

agent: "Go-http-client/1.1"
host: "127.0.0.1:3000"
ip: "127.0.0.1"
level: "recover"
method: "GET"
msg: "crash"
path: "/panic"
rawQuery: "_debug"
refer: ""
reqBody: ""
reqBodySize: 0
requestId: ""
respBody: "{\"code\":\"server-err\",\"message\":\"Fatal Server Error.\"}\n"
respBodySize: 54
status: 500
stack:  log.Panic

func NewLogger

func NewLogger(logger *loggerPkg.Logger) *Logger

func (*Logger) Record

func (l *Logger) Record(c *goa.Context)

Jump to

Keyboard shortcuts

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