| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package featurev1connect |
| 6 |
|
| 7 |
import ( |
| 8 |
connect "connectrpc.com/connect" |
| 9 |
context "context" |
| 10 |
errors "errors" |
| 11 |
v1 "github.com/humanlogio/api/go/svc/feature/v1" |
| 12 |
http "net/http" |
| 13 |
strings "strings" |
| 14 |
) |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
const _ = connect.IsAtLeastVersion1_13_0 |
| 22 |
|
| 23 |
const ( |
| 24 |
|
| 25 |
FeatureServiceName = "svc.feature.v1.FeatureService" |
| 26 |
) |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
const ( |
| 36 |
|
| 37 |
|
| 38 |
FeatureServiceHasFeatureProcedure = "/svc.feature.v1.FeatureService/HasFeature" |
| 39 |
|
| 40 |
|
| 41 |
FeatureServiceListFeatureProcedure = "/svc.feature.v1.FeatureService/ListFeature" |
| 42 |
|
| 43 |
|
| 44 |
FeatureServiceAllowedUsageProcedure = "/svc.feature.v1.FeatureService/AllowedUsage" |
| 45 |
) |
| 46 |
|
| 47 |
|
| 48 |
type FeatureServiceClient interface { |
| 49 |
HasFeature(context.Context, *connect.Request[v1.HasFeatureRequest]) (*connect.Response[v1.HasFeatureResponse], error) |
| 50 |
ListFeature(context.Context, *connect.Request[v1.ListFeatureRequest]) (*connect.Response[v1.ListFeatureResponse], error) |
| 51 |
AllowedUsage(context.Context, *connect.Request[v1.AllowedUsageRequest]) (*connect.Response[v1.AllowedUsageResponse], error) |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
func NewFeatureServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) FeatureServiceClient { |
| 62 |
baseURL = strings.TrimRight(baseURL, "/") |
| 63 |
featureServiceMethods := v1.File_svc_feature_v1_service_proto.Services().ByName("FeatureService").Methods() |
| 64 |
return &featureServiceClient{ |
| 65 |
hasFeature: connect.NewClient[v1.HasFeatureRequest, v1.HasFeatureResponse]( |
| 66 |
httpClient, |
| 67 |
baseURL+FeatureServiceHasFeatureProcedure, |
| 68 |
connect.WithSchema(featureServiceMethods.ByName("HasFeature")), |
| 69 |
connect.WithClientOptions(opts...), |
| 70 |
), |
| 71 |
listFeature: connect.NewClient[v1.ListFeatureRequest, v1.ListFeatureResponse]( |
| 72 |
httpClient, |
| 73 |
baseURL+FeatureServiceListFeatureProcedure, |
| 74 |
connect.WithSchema(featureServiceMethods.ByName("ListFeature")), |
| 75 |
connect.WithClientOptions(opts...), |
| 76 |
), |
| 77 |
allowedUsage: connect.NewClient[v1.AllowedUsageRequest, v1.AllowedUsageResponse]( |
| 78 |
httpClient, |
| 79 |
baseURL+FeatureServiceAllowedUsageProcedure, |
| 80 |
connect.WithSchema(featureServiceMethods.ByName("AllowedUsage")), |
| 81 |
connect.WithClientOptions(opts...), |
| 82 |
), |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
type featureServiceClient struct { |
| 88 |
hasFeature *connect.Client[v1.HasFeatureRequest, v1.HasFeatureResponse] |
| 89 |
listFeature *connect.Client[v1.ListFeatureRequest, v1.ListFeatureResponse] |
| 90 |
allowedUsage *connect.Client[v1.AllowedUsageRequest, v1.AllowedUsageResponse] |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
func (c *featureServiceClient) HasFeature(ctx context.Context, req *connect.Request[v1.HasFeatureRequest]) (*connect.Response[v1.HasFeatureResponse], error) { |
| 95 |
return c.hasFeature.CallUnary(ctx, req) |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
func (c *featureServiceClient) ListFeature(ctx context.Context, req *connect.Request[v1.ListFeatureRequest]) (*connect.Response[v1.ListFeatureResponse], error) { |
| 100 |
return c.listFeature.CallUnary(ctx, req) |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
func (c *featureServiceClient) AllowedUsage(ctx context.Context, req *connect.Request[v1.AllowedUsageRequest]) (*connect.Response[v1.AllowedUsageResponse], error) { |
| 105 |
return c.allowedUsage.CallUnary(ctx, req) |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
type FeatureServiceHandler interface { |
| 110 |
HasFeature(context.Context, *connect.Request[v1.HasFeatureRequest]) (*connect.Response[v1.HasFeatureResponse], error) |
| 111 |
ListFeature(context.Context, *connect.Request[v1.ListFeatureRequest]) (*connect.Response[v1.ListFeatureResponse], error) |
| 112 |
AllowedUsage(context.Context, *connect.Request[v1.AllowedUsageRequest]) (*connect.Response[v1.AllowedUsageResponse], error) |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
func NewFeatureServiceHandler(svc FeatureServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { |
| 121 |
featureServiceMethods := v1.File_svc_feature_v1_service_proto.Services().ByName("FeatureService").Methods() |
| 122 |
featureServiceHasFeatureHandler := connect.NewUnaryHandler( |
| 123 |
FeatureServiceHasFeatureProcedure, |
| 124 |
svc.HasFeature, |
| 125 |
connect.WithSchema(featureServiceMethods.ByName("HasFeature")), |
| 126 |
connect.WithHandlerOptions(opts...), |
| 127 |
) |
| 128 |
featureServiceListFeatureHandler := connect.NewUnaryHandler( |
| 129 |
FeatureServiceListFeatureProcedure, |
| 130 |
svc.ListFeature, |
| 131 |
connect.WithSchema(featureServiceMethods.ByName("ListFeature")), |
| 132 |
connect.WithHandlerOptions(opts...), |
| 133 |
) |
| 134 |
featureServiceAllowedUsageHandler := connect.NewUnaryHandler( |
| 135 |
FeatureServiceAllowedUsageProcedure, |
| 136 |
svc.AllowedUsage, |
| 137 |
connect.WithSchema(featureServiceMethods.ByName("AllowedUsage")), |
| 138 |
connect.WithHandlerOptions(opts...), |
| 139 |
) |
| 140 |
return "/svc.feature.v1.FeatureService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 141 |
switch r.URL.Path { |
| 142 |
case FeatureServiceHasFeatureProcedure: |
| 143 |
featureServiceHasFeatureHandler.ServeHTTP(w, r) |
| 144 |
case FeatureServiceListFeatureProcedure: |
| 145 |
featureServiceListFeatureHandler.ServeHTTP(w, r) |
| 146 |
case FeatureServiceAllowedUsageProcedure: |
| 147 |
featureServiceAllowedUsageHandler.ServeHTTP(w, r) |
| 148 |
default: |
| 149 |
http.NotFound(w, r) |
| 150 |
} |
| 151 |
}) |
| 152 |
} |
| 153 |
|
| 154 |
|
| 155 |
type UnimplementedFeatureServiceHandler struct{} |
| 156 |
|
| 157 |
func (UnimplementedFeatureServiceHandler) HasFeature(context.Context, *connect.Request[v1.HasFeatureRequest]) (*connect.Response[v1.HasFeatureResponse], error) { |
| 158 |
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("svc.feature.v1.FeatureService.HasFeature is not implemented")) |
| 159 |
} |
| 160 |
|
| 161 |
func (UnimplementedFeatureServiceHandler) ListFeature(context.Context, *connect.Request[v1.ListFeatureRequest]) (*connect.Response[v1.ListFeatureResponse], error) { |
| 162 |
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("svc.feature.v1.FeatureService.ListFeature is not implemented")) |
| 163 |
} |
| 164 |
|
| 165 |
func (UnimplementedFeatureServiceHandler) AllowedUsage(context.Context, *connect.Request[v1.AllowedUsageRequest]) (*connect.Response[v1.AllowedUsageResponse], error) { |
| 166 |
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("svc.feature.v1.FeatureService.AllowedUsage is not implemented")) |
| 167 |
} |