Categorygithub.com/luopengift/gohttp
modulepackage
0.0.0-20190418084007-7e989b4239c6
Repository: https://github.com/luopengift/gohttp.git
Documentation: pkg.go.dev

# README

gohttp

BuildStatus GoDoc GoWalker License


gohttp is used for RESTful APIs, Web apps, Http services in Golang. It is used similar with Tornado.

GO verion

GOVERSION >= 1.9.0

Getting started

Sample example

  • Simple Server Application: server
  • Simple Client Application: client

Complete Example

package main

import (
    "net/http"

    "github.com/luopengift/gohttp"
)

type baz struct {
    gohttp.BaseHTTPHandler
}

func (ctx *baz) GET() {
    ctx.Output("baz ok")
}

func main() {
    app := gohttp.Init()
    // register route "/foo"
    app.RouteFunc("/foo", func(resp http.ResponseWriter, req *http.Request) {
        resp.Write([]byte("foo ok"))
    })
    // register route "/bar"
    app.RouteFunCtx("/bar", func(ctx *gohttp.Context) {
        ctx.Output("bar ok")
    })
    // register route "/baz"
    app.Route("/baz", &baz{})
    app.Run(":8888")
}

Download and Install

go get github.com/luopengift/gohttp

Generate https tls cert/key file

go run  $GOROOT/src/crypto/tls/generate_cert.go --host localhost

Run

go run  $GOPATH/src/github.com/luopengift/gohttp/sample/server.go

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Author

@luopengift

License

gohttp source code is licensed under the Apache Licence 2.0.

# Packages

No description provided by the author

# Functions

Init creates a default httpserver instance by default config.
InitConfig init config.
InitLog inits gohttp loghandler.
InitRouterList init route list.
InitTemplate init template.
RegistErrCode regist api error code and msg.
WalkDir walk dir path.

# Constants

VERSION version.

# Variables

Cmdline wapper pprof.Cmdline, default path is /debug/pprof/cmdline.
ErrMap xx.
Index wapper pprof.Index, default path is /debug/pprof/.
Profile wapper pprof.Profile, default path is /debug/pprof/profile.
StartGC 手动触发GC.
StartTrace 运行trace.
StopGC stop gc.
StopTrace 停止trace.
Symbol wapper pprof.Symbol, default path is /debug/pprof/symbol.
Trace wapper pprof.Trace, default path is /debug/pprof/trace.

# Structs

APIHandler designed for http api.
APIOutput is sturct data need responsed.
Application is a httpserver instance.
BaseHTTPHandler http handler.
Config config.
Context gohttp context.
Entry
Entry handle implements HandleHTTP interface.
InfoHandler info handler.
RouteHandler routehandler.

# Interfaces

HandleHTTP handle http interface.
Handler implements http handler interface.
Logger interface.
ResponseWriter is a wrapper around http.ResponseWriter that provides extra information about the response.

# Type aliases

HandleFunc handle func.
HandleFunCtx handle fun ctx.
RouterList router List.
Template template.