https://github.com/bugfan/srv
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/bugfan/srv
- Owner: bugfan
- Created: 2019-12-16T09:01:36.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-03-11T02:34:58.000Z (over 4 years ago)
- Last Synced: 2024-06-20T17:29:41.644Z (almost 2 years ago)
- Language: Go
- Size: 9.77 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Golang http handler
## Installation
```
go get -u github.com/bugfan/srv
```
## Usage
[Refer to this test file](https://github.com/bugfan/srv/blob/master/srv_test.go "test file")
```
addr := ":8080"
s := srv.New("addr")
// set head middleware
s.AddHeadHandler(&zlog{}, &auth{})
// set tail middleware
s.AddTailHandler(&zlog{})
// set your handler
s.Handle("/", &yourHandler{})
s.Handle("/ws/", &yourWebsocketHandler{})
s.Handle("/static/", &yourStaticHandler{})
/*
* if hava tls certificate data
*/
// keyData := []byte("xxxx")
// certData := []byte("xxxx")
// s.SetTLSConfigFromBytes(certData, keyData)
/*
* if hava tls config
*/
// tlsconfig := &tls.Config{}
// s.SetTLSConfig(tlsconfig)
// listen s
/*
* method 1
* run directly
*/
s.Run()
/*
* method 2
* if you have own listener
*/
// http.ListenAndServe(addr, s)
```