github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/cmd/srv-applet-mgr/apis/root.go (about)

     1  package apis
     2  
     3  import (
     4  	"github.com/machinefi/w3bstream/cmd/srv-applet-mgr/apis/account"
     5  	"github.com/machinefi/w3bstream/cmd/srv-applet-mgr/apis/account_access_key"
     6  	"github.com/machinefi/w3bstream/cmd/srv-applet-mgr/apis/applet"
     7  	"github.com/machinefi/w3bstream/cmd/srv-applet-mgr/apis/configuration"
     8  	"github.com/machinefi/w3bstream/cmd/srv-applet-mgr/apis/cronjob"
     9  	"github.com/machinefi/w3bstream/cmd/srv-applet-mgr/apis/debug"
    10  	"github.com/machinefi/w3bstream/cmd/srv-applet-mgr/apis/deploy"
    11  	"github.com/machinefi/w3bstream/cmd/srv-applet-mgr/apis/event"
    12  	"github.com/machinefi/w3bstream/cmd/srv-applet-mgr/apis/login"
    13  	"github.com/machinefi/w3bstream/cmd/srv-applet-mgr/apis/middleware"
    14  	"github.com/machinefi/w3bstream/cmd/srv-applet-mgr/apis/monitor"
    15  	"github.com/machinefi/w3bstream/cmd/srv-applet-mgr/apis/operator"
    16  	"github.com/machinefi/w3bstream/cmd/srv-applet-mgr/apis/project"
    17  	"github.com/machinefi/w3bstream/cmd/srv-applet-mgr/apis/project_config"
    18  	"github.com/machinefi/w3bstream/cmd/srv-applet-mgr/apis/projectoperator"
    19  	"github.com/machinefi/w3bstream/cmd/srv-applet-mgr/apis/publisher"
    20  	"github.com/machinefi/w3bstream/cmd/srv-applet-mgr/apis/resource"
    21  	"github.com/machinefi/w3bstream/cmd/srv-applet-mgr/apis/strategy"
    22  	"github.com/machinefi/w3bstream/cmd/srv-applet-mgr/apis/traffic_limit"
    23  	"github.com/machinefi/w3bstream/cmd/srv-applet-mgr/apis/version"
    24  	"github.com/machinefi/w3bstream/cmd/srv-applet-mgr/apis/wasmlog"
    25  	confhttp "github.com/machinefi/w3bstream/pkg/depends/conf/http"
    26  	"github.com/machinefi/w3bstream/pkg/depends/conf/jwt"
    27  	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport"
    28  	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/openapi"
    29  	"github.com/machinefi/w3bstream/pkg/depends/kit/kit"
    30  )
    31  
    32  var (
    33  	RootMgr   = kit.NewRouter(httptransport.Group("/"))
    34  	RootEvent = kit.NewRouter(httptransport.Group("/"))
    35  	RootDebug = kit.NewRouter(httptransport.Group("/"))
    36  )
    37  
    38  func init() {
    39  	// root router register for applet-mgr
    40  	{
    41  		serve := kit.NewRouter(httptransport.Group("/srv-applet-mgr"))
    42  		RootMgr.Register(serve)
    43  		RootMgr.Register(kit.NewRouter(&version.VersionRouter{}))
    44  		RootMgr.Register(kit.NewRouter(&confhttp.Liveness{}))
    45  
    46  		var (
    47  			v0   = kit.NewRouter(httptransport.Group("/v0"))
    48  			auth = kit.NewRouter(&jwt.Auth{}, &middleware.ContextAccountAuth{})
    49  		)
    50  		serve.Register(v0)
    51  		serve.Register(kit.NewRouter(&openapi.OpenAPI{}))
    52  
    53  		v0.Register(login.Root)
    54  		v0.Register(account.RegisterRoot)
    55  		v0.Register(configuration.Root)
    56  		v0.Register(auth)
    57  
    58  		auth.Register(account.Root)
    59  		auth.Register(account_access_key.Root)
    60  		auth.Register(project.Root)
    61  		auth.Register(project_config.Root)
    62  		auth.Register(applet.Root)
    63  		auth.Register(deploy.Root)
    64  		auth.Register(publisher.Root)
    65  		auth.Register(strategy.Root)
    66  		auth.Register(monitor.Root)
    67  		auth.Register(cronjob.Root)
    68  		auth.Register(resource.Root)
    69  		auth.Register(wasmlog.Root)
    70  		auth.Register(operator.Root)
    71  		auth.Register(traffic_limit.Root)
    72  		auth.Register(projectoperator.Root)
    73  	}
    74  
    75  	// root router register for event http transport
    76  	{
    77  		// TODO should use another root name to differentiate with w3bstream core? `/srv-event`
    78  		serve := kit.NewRouter(httptransport.Group("/srv-applet-mgr"))
    79  		RootEvent.Register(serve)
    80  		RootEvent.Register(kit.NewRouter(&version.VersionRouter{}))
    81  		RootEvent.Register(kit.NewRouter(&confhttp.Liveness{}))
    82  
    83  		var (
    84  			v0   = kit.NewRouter(httptransport.Group("/v0"))
    85  			auth = kit.NewRouter(&jwt.Auth{}, &middleware.ContextPublisherAuth{})
    86  		)
    87  		serve.Register(kit.NewRouter(&openapi.OpenAPI{}))
    88  		serve.Register(v0)
    89  
    90  		v0.Register(auth)
    91  
    92  		auth.Register(event.Root)
    93  	}
    94  
    95  	{
    96  		serve := kit.NewRouter(httptransport.Group("/srv-applet-mgr"))
    97  		RootDebug.Register(serve)
    98  
    99  		v0 := kit.NewRouter(httptransport.Group("/v0"))
   100  		serve.Register(kit.NewRouter(&openapi.OpenAPI{}))
   101  		serve.Register(v0)
   102  		v0.Register(debug.Root)
   103  	}
   104  }