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:
39
examples/redirect/main.go
Normal file
39
examples/redirect/main.go
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user