Skip to content

Commit

Permalink
Add APIName constant to generated code (#3445)
Browse files Browse the repository at this point in the history
Useful to configure telemetry.
  • Loading branch information
raphael committed Jan 12, 2024
1 parent e24da9e commit 28c8f05
Show file tree
Hide file tree
Showing 3 changed files with 267 additions and 132 deletions.
9 changes: 6 additions & 3 deletions codegen/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,17 @@ type Auther interface {
}
{{- end }}
// APIName is the name of the API as defined in the design.
const APIName = {{ printf "%q" .APIName }}
// APIVersion is the version of the API as defined in the design.
const APIVersion = {{ printf "%q" .APIVersion }}
// ServiceName is the name of the service as defined in the design. This is the
// same value that is set in the endpoint request contexts under the ServiceKey
// key.
const ServiceName = {{ printf "%q" .Name }}
// APIVersion is the version of the API as defined in the design.
const APIVersion = {{ printf "%q" .APIVersion }}
// MethodNames lists the service method names as defined in the design. These
// are the same values that are set in the endpoint request contexts under the
// MethodKey key.
Expand Down
3 changes: 3 additions & 0 deletions codegen/service/service_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ type (
Name string
// Description is the service description.
Description string
// APIName is the name of the API the service belongs to.
APIName string
// APIVersion is the API version.
APIVersion string
// StructName is the service struct name.
Expand Down Expand Up @@ -749,6 +751,7 @@ func (d ServicesData) analyze(service *expr.ServiceExpr) *Data {
data := &Data{
Name: service.Name,
Description: desc,
APIName: expr.Root.API.Name,
APIVersion: expr.Root.API.Version,
VarName: varName,
PathName: codegen.SnakeCase(varName),
Expand Down

0 comments on commit 28c8f05

Please sign in to comment.