aboutsummaryrefslogtreecommitdiff
path: root/_examples/headers/main.go
diff options
context:
space:
mode:
authorAlexander Kiryukhin <a.kiryukhin@mail.ru>2022-01-05 21:21:51 +0300
committerAlexander Kiryukhin <a.kiryukhin@mail.ru>2022-01-05 21:21:51 +0300
commitb3c48f806724b82b649c89aa5e0d07a09e414140 (patch)
tree61b5925b2a25c74d1966b757be23168a2663a227 /_examples/headers/main.go
parentd36bd3f0aa6ee962cc1a0d40bfb6a428da4ff93b (diff)
Added interfaces
Diffstat (limited to '_examples/headers/main.go')
-rw-r--r--_examples/headers/main.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/_examples/headers/main.go b/_examples/headers/main.go
new file mode 100644
index 0000000..d0ab968
--- /dev/null
+++ b/_examples/headers/main.go
@@ -0,0 +1,53 @@
+package main
+
+import (
+ "context"
+ "fmt"
+ "log"
+ "net/http"
+
+ "github.com/gogeneric/api"
+)
+
+func main() {
+ h := &http.Server{Addr: "0.0.0.0:3000"}
+ mux := http.NewServeMux()
+ h.Handler = mux
+
+ // Here is magic!
+ mux.Handle("/hello", api.Wrap(handleHello))
+
+ if err := h.ListenAndServe(); err != http.ErrServerClosed {
+ log.Fatalln(err)
+ }
+}
+
+func handleHello(ctx context.Context, req *helloRequest) (*helloResponse, error) {
+ return &helloResponse{Message: fmt.Sprintf("Hello, %s!", req.Name)}, nil
+}
+
+type helloRequest struct {
+ Name string `json:"name"`
+ User string
+}
+
+// SetHeaders implements api.WithHeader interface
+func (h *helloRequest) WithHeader(header http.Header) {
+ h.User = header.Get("user")
+}
+
+type helloResponse struct {
+ Message string `json:"message"`
+}
+
+func test[T IN](x T) {
+
+}
+
+type IN interface {
+ string | int | inter
+}
+
+type inter interface {
+ String() string
+}