1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-24 10:07:04 +02:00
go-micro/examples/redirect/main.go
2020-12-26 15:17:20 +00:00

40 lines
682 B
Go

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)
}
}