本文整理汇总了Golang中github.com/labstack/gommon/log.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestEcho
func TestEcho(t *testing.T) {
e := New()
req, _ := http.NewRequest(GET, "/", nil)
rec := httptest.NewRecorder()
c := NewContext(req, NewResponse(rec, e), e)
// Router
assert.NotNil(t, e.Router())
// Debug
e.SetDebug(true)
assert.True(t, e.debug)
// DefaultHTTPErrorHandler
e.DefaultHTTPErrorHandler(errors.New("error"), c)
assert.Equal(t, http.StatusInternalServerError, rec.Code)
// Logger
l := log.New("test")
e.SetLogger(l)
assert.Equal(t, l, e.Logger())
// Autoindex
e.AutoIndex(true)
assert.True(t, e.autoIndex)
}
开发者ID:cnhans,项目名称:echo,代码行数:26,代码来源:echo_test.go
示例2: New
// New creates an instance of Echo.
func New() (e *Echo) {
e = &Echo{maxParam: new(int)}
e.pool.New = func() interface{} {
return NewContext(nil, new(Response), e)
}
e.router = NewRouter(e)
//----------
// Defaults
//----------
e.HTTP2(true)
e.defaultHTTPErrorHandler = func(err error, c *Context) {
code := http.StatusInternalServerError
msg := http.StatusText(code)
if he, ok := err.(*HTTPError); ok {
code = he.code
msg = he.message
}
if e.debug {
msg = err.Error()
}
if !c.response.committed {
http.Error(c.response, msg, code)
}
e.logger.Error(err)
}
e.SetHTTPErrorHandler(e.defaultHTTPErrorHandler)
e.SetBinder(&binder{})
// Logger
e.logger = log.New("echo")
return
}
开发者ID:cnhans,项目名称:echo,代码行数:36,代码来源:echo.go
示例3: TestResponseWriteHeader
func TestResponseWriteHeader(t *testing.T) {
rec := httptest.NewRecorder()
res := NewResponse(rec, log.New("test"))
res.WriteHeader(http.StatusOK)
assert.True(t, res.Committed())
assert.Equal(t, http.StatusOK, res.Status())
}
开发者ID:o1egl,项目名称:echo,代码行数:7,代码来源:response_test.go
示例4: NewConfig
func NewConfig(c *engine.Config) (s *Server) {
s = &Server{
Server: new(http.Server),
config: c,
pool: &Pool{
request: sync.Pool{
New: func() interface{} {
return &Request{}
},
},
response: sync.Pool{
New: func() interface{} {
return &Response{logger: s.logger}
},
},
header: sync.Pool{
New: func() interface{} {
return &Header{}
},
},
url: sync.Pool{
New: func() interface{} {
return &URL{}
},
},
},
handler: engine.HandlerFunc(func(req engine.Request, res engine.Response) {
s.logger.Fatal("handler not set")
}),
logger: log.New("echo"),
}
return
}
开发者ID:efimovalex,项目名称:EventKitAPI,代码行数:33,代码来源:server.go
示例5: NewFromConfig
// NewFromConfig returns an instance of `standard.Server` from config.
func NewFromConfig(c engine.Config) (s *Server) {
s = &Server{
Server: new(http.Server),
config: c,
pool: &pool{
request: sync.Pool{
New: func() interface{} {
return &Request{logger: s.logger}
},
},
response: sync.Pool{
New: func() interface{} {
return &Response{logger: s.logger}
},
},
header: sync.Pool{
New: func() interface{} {
return &Header{}
},
},
url: sync.Pool{
New: func() interface{} {
return &URL{}
},
},
},
handler: engine.HandlerFunc(func(rq engine.Request, rs engine.Response) {
s.logger.Error("handler not set, use `SetHandler()` to set it.")
}),
logger: log.New("echo"),
}
s.Addr = c.Address
s.Handler = s
return
}
开发者ID:ggoblin,项目名称:goblin,代码行数:36,代码来源:server.go
示例6: TestLoggerIPAddress
func TestLoggerIPAddress(t *testing.T) {
e := echo.New()
l := log.New("echo")
buf := new(bytes.Buffer)
l.SetOutput(buf)
e.SetLogger(l)
req, _ := http.NewRequest(echo.GET, "/", nil)
rec := httptest.NewRecorder()
c := echo.NewContext(req, echo.NewResponse(rec, e), e)
ip := "127.0.0.1"
h := func(c *echo.Context) error {
return c.String(http.StatusOK, "test")
}
mw := Logger()
// With X-Real-IP
req.Header.Add(echo.XRealIP, ip)
mw(h)(c)
assert.Contains(t, buf.String(), ip)
// With X-Forwarded-For
buf.Reset()
req.Header.Del(echo.XRealIP)
req.Header.Add(echo.XForwardedFor, ip)
mw(h)(c)
assert.Contains(t, buf.String(), ip)
// with req.RemoteAddr
buf.Reset()
mw(h)(c)
assert.Contains(t, buf.String(), ip)
}
开发者ID:goben-ch,项目名称:gobench,代码行数:33,代码来源:logger_test.go
示例7: TestResponseWrite
func TestResponseWrite(t *testing.T) {
c := new(fasthttp.RequestCtx)
res := NewResponse(c, log.New("test"))
res.Write([]byte("test"))
assert.Equal(t, int64(4), res.Size())
assert.Equal(t, "test", string(c.Response.Body()))
}
开发者ID:ZloyDyadka,项目名称:echo,代码行数:7,代码来源:response_test.go
示例8: TestResponseWriteHeader
func TestResponseWriteHeader(t *testing.T) {
c := new(fasthttp.RequestCtx)
res := NewResponse(c, log.New("test"))
res.WriteHeader(http.StatusOK)
assert.True(t, res.Committed())
assert.Equal(t, http.StatusOK, res.Status())
}
开发者ID:ZloyDyadka,项目名称:echo,代码行数:7,代码来源:response_test.go
示例9: TestRequest
func TestRequest(t *testing.T) {
ctx := new(fast.RequestCtx)
url, _ := url.Parse("http://github.com/labstack/echo")
ctx.Init(&fast.Request{}, fakeAddr{addr: "127.0.0.1"}, nil)
ctx.Request.Read(bufio.NewReader(bytes.NewBufferString(test.MultipartRequest)))
ctx.Request.SetRequestURI(url.String())
test.RequestTest(t, NewRequest(ctx, log.New("echo")))
}
开发者ID:ZloyDyadka,项目名称:echo,代码行数:8,代码来源:request_test.go
示例10: TestResponseSetCookie
func TestResponseSetCookie(t *testing.T) {
rec := httptest.NewRecorder()
res := NewResponse(rec, log.New("test"))
res.SetCookie(&Cookie{&http.Cookie{
Name: "name",
Value: "Jon Snow",
}})
assert.Equal(t, "name=Jon Snow", rec.Header().Get("Set-Cookie"))
}
开发者ID:o1egl,项目名称:echo,代码行数:9,代码来源:response_test.go
示例11: TestResponseWrite
func TestResponseWrite(t *testing.T) {
rec := httptest.NewRecorder()
res := NewResponse(rec, log.New("test"))
res.Write([]byte("test"))
assert.Equal(t, int64(4), res.Size())
assert.Equal(t, "test", rec.Body.String())
res.Flush()
assert.True(t, rec.Flushed)
}
开发者ID:o1egl,项目名称:echo,代码行数:9,代码来源:response_test.go
示例12: New
func New(templateDir string) tplex.TemplateEx {
a := &templatePongo2{
templateDir: templateDir,
ext: `.html`,
Logger: log.New("tplex"),
}
a.templateDir, _ = filepath.Abs(templateDir)
return a
}
开发者ID:webx-top,项目名称:webx,代码行数:9,代码来源:pongo2.go
示例13: TestEchoLogger
func TestEchoLogger(t *testing.T) {
e := New()
l := log.New("test")
e.SetLogger(l)
assert.Equal(t, l, e.Logger())
e.SetLogOutput(ioutil.Discard)
assert.Equal(t, l.Output(), ioutil.Discard)
e.SetLogLevel(log.OFF)
assert.Equal(t, l.Level(), log.OFF)
}
开发者ID:AlekSi,项目名称:echo,代码行数:10,代码来源:echo_test.go
示例14: NewResponseRecorder
func NewResponseRecorder() *ResponseRecorder {
rec := httptest.NewRecorder()
return &ResponseRecorder{
Response: &Response{
response: rec,
header: &Header{rec.Header()},
writer: rec,
logger: log.New("test"),
},
Body: rec.Body,
}
}
开发者ID:ZloyDyadka,项目名称:echo,代码行数:12,代码来源:response.go
示例15: TestResponseSetCookie
func TestResponseSetCookie(t *testing.T) {
c := new(fasthttp.RequestCtx)
res := NewResponse(c, log.New("test"))
cookie := new(fasthttp.Cookie)
cookie.SetKey("name")
cookie.SetValue("Jon Snow")
res.SetCookie(&Cookie{cookie})
c.Response.Header.SetCookie(cookie)
ck := new(fasthttp.Cookie)
ck.SetKey("name")
assert.True(t, c.Response.Header.Cookie(ck))
assert.Equal(t, "Jon Snow", string(ck.Value()))
}
开发者ID:ZloyDyadka,项目名称:echo,代码行数:13,代码来源:response_test.go
示例16: New
// New creates an instance of Echo.
func New() (e *Echo) {
e = &Echo{maxParam: new(int)}
e.pool.New = func() interface{} {
return e.NewContext(nil, nil)
}
e.router = NewRouter(e)
// Defaults
e.SetHTTPErrorHandler(e.DefaultHTTPErrorHandler)
e.SetBinder(&binder{})
e.logger = log.New("echo")
e.logger.SetLevel(log.ERROR)
return
}
开发者ID:efimovalex,项目名称:EventKitAPI,代码行数:16,代码来源:echo.go
示例17: New
func New(templateDir string) TemplateEx {
t := &templateEx{
CachedRelation: make(map[string]*CcRel),
TemplateDir: templateDir,
DelimLeft: "{{",
DelimRight: "}}",
IncludeTag: "Include",
ExtendTag: "Extend",
BlockTag: "Block",
SuperTag: "Super",
Ext: ".html",
Debug: Debug,
}
t.Logger = log.New("tplex")
t.Logger.SetLevel(log.INFO)
t.InitRegexp()
return t
}
开发者ID:webx-top,项目名称:webx,代码行数:18,代码来源:ex.go
示例18: realMain
func realMain() int {
// reads and parses application config params
config, err := config.ReadFromFile("./config.json")
if err != nil {
fmt.Println("Config file reading error. Details: ", err)
return 1
}
// creates Logger (can be replaced with other popular logger)
log := log.New("GOB ")
log.Debug("Application launched")
// creates Backend object
back, err := backend.New(&config.Backend, log)
if err != nil {
log.Error("Backend initialisation error. Details: ", err)
return 2
}
// creates Frontend objects
front, err := frontend.New(&config.Frontend, log, back)
if err != nil {
log.Error("Frontend initialisation error. Details: ", err)
return 3
}
// starts background processes
if err := back.Start(); err != nil {
log.Error("Backend processes launching error. Details: ", err)
return 4
}
// starts HTTP listener and handlers
if err := front.Start(); err != nil {
log.Error("Frontend listeners/processes error. Details: ", err)
return 5
}
log.Info("Application succesfully terminated")
return 0
}
开发者ID:goben-ch,项目名称:gobench,代码行数:42,代码来源:main.go
示例19: WithConfig
// WithConfig returns `Server` instance with provided config.
func WithConfig(c engine.Config) (s *Server) {
s = &Server{
Server: new(http.Server),
config: c,
pool: &pool{
request: sync.Pool{
New: func() interface{} {
return &Request{logger: s.logger}
},
},
response: sync.Pool{
New: func() interface{} {
return &Response{logger: s.logger}
},
},
responseAdapter: sync.Pool{
New: func() interface{} {
return &responseAdapter{}
},
},
header: sync.Pool{
New: func() interface{} {
return &Header{}
},
},
url: sync.Pool{
New: func() interface{} {
return &URL{}
},
},
},
handler: engine.HandlerFunc(func(req engine.Request, res engine.Response) {
panic("echo: handler not set, use `Server#SetHandler()` to set it.")
}),
logger: glog.New("echo"),
}
s.ReadTimeout = c.ReadTimeout
s.WriteTimeout = c.WriteTimeout
s.Addr = c.Address
s.Handler = s
return
}
开发者ID:flike,项目名称:kingshard,代码行数:43,代码来源:server.go
示例20: New
// New creates an instance of Echo.
func New() (e *Echo) {
e = &Echo{maxParam: new(int)}
e.pool.New = func() interface{} {
return NewContext(nil, new(Response), e)
}
e.router = NewRouter(e)
//----------
// Defaults
//----------
e.SetHTTPErrorHandler(e.DefaultHTTPErrorHandler)
e.SetBinder(&binder{})
// Logger
e.logger = log.New("echo")
e.SetLogLevel(log.FATAL)
return
}
开发者ID:otsimo,项目名称:distribution,代码行数:21,代码来源:echo.go
注:本文中的github.com/labstack/gommon/log.New函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论