Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rjeczalik/powermux
https://github.com/rjeczalik/powermux
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/rjeczalik/powermux
- Owner: rjeczalik
- License: mit
- Created: 2015-07-12T16:33:02.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-07-13T14:30:40.000Z (over 9 years ago)
- Last Synced: 2024-05-01T23:45:25.573Z (8 months ago)
- Language: Go
- Size: 137 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# powermux
Effortless HTTP routing for REST API servers.# example
```go
package mainimport (
"errors""github.com/rjeczalik/powermux"
)type Service struct{}
type EchoArg struct {
Text string `query:"text"`
}type EchoReply struct {
Text string `json:"text"`
}func (Service) Echo(arg *EchoArg, reply *EchoReply) error {
if arg.Text == "" {
return powermux.NewError(40001, errors.New("text cannot be empty"))
}
reply.Text = arg.Text
return nil
}var routes = powermux.Routes{{
Method: "GET",
Path: "/echo",
Handler: (Service).Echo,
}}func main() {
srv := powermux.NewServer(":8080", Service{}, routes)if err := srv.ListenAndServe(); err != nil {
panic(err)
}
}
```
```
~ $ go run example.go
2015/07/08 08:19:59 powermux: using TCP keep-alive for [::]:8080
2015/07/08 08:21:25 powermux: 127.0.0.1:61155: 400 GET /v1/echo arg=&main.EchoArg{Text:""} reply=&main.EchoReply{Text:""} err=text cannot be empty (code 40001)
2015/07/08 08:21:37 powermux: 127.0.0.1:61156: 200 GET /v1/echo arg=&main.EchoArg{Text:"XD"} reply=&main.EchoReply{Text:"XD"}
```