1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-02-10 18:31:40 +02:00
2021-01-20 21:28:48 +00:00

40 lines
683 B
Go

package main
import (
"log"
"context"
"github.com/asim/go-micro/v3"
api "github.com/asim/go-micro/v3/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)
}
}