package userservice import ( "context" "galaxy/gateway/internal/downstream" usermodel "galaxy/model/user" ) var noOpClose = func() error { return nil } // NewRoutes returns the reserved authenticated gateway routes owned by the // Gateway -> User self-service boundary. // // When baseURL is empty, the returned routes still reserve the stable // `user.*` message types but resolve them to a dependency-unavailable client // so callers receive the transport-level unavailable outcome instead of a // route-miss error. func NewRoutes(baseURL string) (map[string]downstream.Client, func() error, error) { client := downstream.Client(unavailableClient{}) closeFn := noOpClose if baseURL != "" { httpClient, err := NewHTTPClient(baseURL) if err != nil { return nil, nil, err } client = httpClient closeFn = httpClient.Close } return map[string]downstream.Client{ usermodel.MessageTypeGetMyAccount: client, usermodel.MessageTypeUpdateMyProfile: client, usermodel.MessageTypeUpdateMySettings: client, }, closeFn, nil } type unavailableClient struct{} func (unavailableClient) ExecuteCommand(context.Context, downstream.AuthenticatedCommand) (downstream.UnaryResult, error) { return downstream.UnaryResult{}, downstream.ErrDownstreamUnavailable } var _ downstream.Client = unavailableClient{}