1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-11-29 21:47:44 +02:00

Add examples

This commit is contained in:
Asim Aslam
2020-12-26 15:17:20 +00:00
parent 273bab5dd7
commit a34c70de0e
320 changed files with 20803 additions and 0 deletions

39
examples/redirect/main.go Normal file
View File

@@ -0,0 +1,39 @@
package main
import (
"log"
"context"
"github.com/micro/go-micro/v2"
api "github.com/micro/micro/v2/api/proto"
)
type Redirect struct{}
func (r *Redirect) Url(ctx context.Context, req *api.Request, rsp *api.Response) error {
rsp.StatusCode = int32(301)
rsp.Header = map[string]*api.Pair{
"Location": &api.Pair{
Key: "Location",
Values: []string{"https://google.com"},
},
}
return nil
}
func main() {
service := micro.NewService(
micro.Name("go.micro.api.redirect"),
)
// parse command line flags
service.Init()
service.Server().Handle(
service.Server().NewHandler(new(Redirect)),
)
if err := service.Run(); err != nil {
log.Fatal(err)
}
}