-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from RussellLuo/multi-http-ops
annotation: Add support for multiple HTTP operations
- Loading branch information
Showing
16 changed files
with
705 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# messaging | ||
|
||
This example illustrates how to specify multiple HTTP operations. | ||
|
||
|
||
## Generate the code | ||
|
||
```bash | ||
$ go generate | ||
``` | ||
|
||
## Test the server | ||
|
||
Run the server: | ||
|
||
```bash | ||
$ go run cmd/main.go | ||
2022/02/26 17:45:20 transport=HTTP addr=:8080 | ||
``` | ||
|
||
Get a message: | ||
|
||
```bash | ||
$ curl -XGET 'http://localhost:8080/messages/123456' | ||
{"text":"user[]: message[123456]"} | ||
``` | ||
|
||
Get a message from a specific user: | ||
|
||
```bash | ||
$ curl -XGET 'http://localhost:8080/users/me/messages/123456' | ||
{"text":"user[me]: message[123456]"} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
"github.com/RussellLuo/kun/examples/messaging" | ||
"github.com/RussellLuo/kun/pkg/httpcodec" | ||
) | ||
|
||
func main() { | ||
httpAddr := flag.String("http.addr", ":8080", "HTTP listen address") | ||
flag.Parse() | ||
|
||
svc := &messaging.Messaging{} | ||
r := messaging.NewHTTPRouter(svc, httpcodec.NewDefaultCodecs(nil)) | ||
|
||
errs := make(chan error, 2) | ||
go func() { | ||
log.Printf("transport=HTTP addr=%s\n", *httpAddr) | ||
errs <- http.ListenAndServe(*httpAddr, r) | ||
}() | ||
go func() { | ||
c := make(chan os.Signal, 1) | ||
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM) | ||
errs <- fmt.Errorf("%s", <-c) | ||
}() | ||
|
||
log.Printf("terminated, err:%v", <-errs) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.