Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add status api to detect api ready #313

Merged
merged 2 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions api/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net"
"net/http"

"github.com/etherlabsio/healthcheck/v2"
"github.com/filecoin-project/go-jsonrpc"
"github.com/filecoin-project/venus-auth/jwtclient"
"github.com/filecoin-project/venus/venus-shared/api/messager"
Expand Down Expand Up @@ -46,13 +47,15 @@ func BindRateLimit(msgImp *MessageImp, remoteAuthCli jwtclient.IAuthClient, rate
func RunAPI(lc fx.Lifecycle, localAuthCli *jwtclient.LocalAuthClient, remoteAuthCli jwtclient.IAuthClient, lst net.Listener, msgImp messager.IMessager) error {
srv := jsonrpc.NewServer()
srv.Register("Message", msgImp)
handler := http.NewServeMux()
handler.Handle("/rpc/v0", srv)
authMux := jwtclient.NewAuthMux(localAuthCli, jwtclient.WarpIJwtAuthClient(remoteAuthCli), handler)
authMux.TrustHandle("/debug/pprof/", http.DefaultServeMux)
authMux := jwtclient.NewAuthMux(localAuthCli, jwtclient.WarpIJwtAuthClient(remoteAuthCli), srv)

mux := http.NewServeMux()
mux.Handle("/rpc/v0", authMux)
mux.Handle("/debug/pprof/", http.DefaultServeMux)
mux.Handle("/healthcheck", healthcheck.Handler())

apiserv := &http.Server{
Handler: authMux,
Handler: mux,
}
lc.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func DefaultConfig() *Config {
Level: "info",
},
API: APIConfig{
Address: "/ip4/0.0.0.0/tcp/39812",
Address: "/ip4/127.0.0.1/tcp/39812",
},
Node: NodeConfig{
Url: "/ip4/127.0.0.1/tcp/3453",
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/DATA-DOG/go-sqlmock v1.5.0
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef
github.com/etherlabsio/healthcheck/v2 v2.0.0
github.com/fatih/color v1.13.0
github.com/filecoin-project/go-address v1.1.0
github.com/filecoin-project/go-bitfield v0.2.4
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.m
github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0=
github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/etherlabsio/healthcheck/v2 v2.0.0 h1:oKq8cbpwM/yNGPXf2Sff6MIjVUjx/pGYFydWzeK2MpA=
github.com/etherlabsio/healthcheck/v2 v2.0.0/go.mod h1:huNVOjKzu6FI1eaO1CGD3ZjhrmPWf5Obu/pzpI6/wog=
github.com/facebookgo/atomicfile v0.0.0-20151019160806-2de1f203e7d5/go.mod h1:JpoxHjuQauoxiFMl1ie8Xc/7TfLuMZ5eOCONd1sUBHg=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.8.0/go.mod h1:3l45GVGkyrnYNl9HoIjnp2NnNWvh6hLAqD8yTfGjnw8=
Expand Down
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ var runCmd = &cli.Command{
Name: "run",
Usage: "run messager",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "listen",
Usage: "specify endpoint for listen",
Value: "/ip4/127.0.0.1/tcp/39812",
},
&cli.StringFlag{
Name: "auth-url",
Usage: "url for auth server",
Expand Down Expand Up @@ -326,6 +331,10 @@ func runAction(cctx *cli.Context) error {
}

func updateFlag(cfg *config.Config, ctx *cli.Context) error {
if ctx.IsSet("listen") {
cfg.API.Address = ctx.String("listen")
}

if ctx.IsSet("auth-url") {
cfg.JWT.AuthURL = ctx.String("auth-url")
}
Expand Down