parent
c114f5c96b
commit
8c26c8c328
@ -0,0 +1,36 @@ |
||||
package main |
||||
|
||||
import ( |
||||
"log" |
||||
|
||||
"github.com/go-kratos/kratos/v2" |
||||
"github.com/go-kratos/kratos/v2/transport/http" |
||||
"github.com/gorilla/handlers" |
||||
) |
||||
|
||||
func hello(ctx http.Context) error { |
||||
name := ctx.Vars().Get("name") |
||||
return ctx.String(200, "hellowolrd "+name) |
||||
} |
||||
|
||||
func main() { |
||||
httpSrv := http.NewServer( |
||||
http.Address(":8000"), |
||||
http.Filter(handlers.CORS( |
||||
handlers.AllowedOrigins([]string{"*"}), |
||||
handlers.AllowedHeaders([]string{"GET", "POST"}), |
||||
)), |
||||
) |
||||
route := httpSrv.Route("/") |
||||
route.GET("/helloworld/{name}", hello) |
||||
|
||||
app := kratos.New( |
||||
kratos.Name("cors"), |
||||
kratos.Server( |
||||
httpSrv, |
||||
), |
||||
) |
||||
if err := app.Run(); err != nil { |
||||
log.Fatal(err) |
||||
} |
||||
} |
Loading…
Reference in new issue