Skip to content

Commit

Permalink
updating clientconfig struct
Browse files Browse the repository at this point in the history
  • Loading branch information
rpatali committed Aug 9, 2019
1 parent a232106 commit c4b3be5
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 44 deletions.
26 changes: 8 additions & 18 deletions codegen/client.go
Expand Up @@ -34,18 +34,8 @@ type clientConfig interface {
h *PackageHelper) (*ClientSpec, error)
}

// ClientThriftConfig is the "config" field in the client-config.yaml for http
// client and tchannel client.
type ClientThriftConfig struct {
ExposedMethods map[string]string `yaml:"exposedMethods" json:"exposedMethods" validate:"exposedMethods"`
ThriftFile string `yaml:"thriftFile" json:"thriftFile" validate:"nonzero"`
ThriftFileSha string `yaml:"thriftFileSha,omitempty" json:"thriftFileSha"`
SidecarRouter string `yaml:"sidecarRouter" json:"sidecarRouter"`
Fixture *Fixture `yaml:"fixture,omitempty" json:"fixture"`
}

// ClientIDLConfig is the "config" field in the client-config.yaml for gRPC clients.
// This struct is generic and can be used to replace HTTP/TChannel client config as well.
// ClientIDLConfig is the "config" field in the client-config.yaml for
// HTTP/TChannel/gRPC clients.
type ClientIDLConfig struct {
ExposedMethods map[string]string `yaml:"exposedMethods" json:"exposedMethods" validate:"exposedMethods"`
IDLFile string `yaml:"idlFile" json:"idlFile" validate:"nonzero"`
Expand Down Expand Up @@ -95,8 +85,8 @@ func validateExposedMethods(v interface{}, param string) error {
// HTTPClientConfig represents the "config" field for a HTTP client-config.yaml
type HTTPClientConfig struct {
ClassConfigBase `yaml:",inline" json:",inline"`
Dependencies Dependencies `yaml:"dependencies,omitempty" json:"dependencies"`
Config *ClientThriftConfig `yaml:"config" json:"config" validate:"nonzero"`
Dependencies Dependencies `yaml:"dependencies,omitempty" json:"dependencies"`
Config *ClientIDLConfig `yaml:"config" json:"config" validate:"nonzero"`
}

func newHTTPClientConfig(raw []byte) (*HTTPClientConfig, error) {
Expand All @@ -117,12 +107,12 @@ func newHTTPClientConfig(raw []byte) (*HTTPClientConfig, error) {

func newClientSpec(
clientType string,
config *ClientThriftConfig,
config *ClientIDLConfig,
instance *ModuleInstance,
h *PackageHelper,
annotate bool,
) (*ClientSpec, error) {
thriftFile := filepath.Join(h.ThriftIDLPath(), config.ThriftFile)
thriftFile := filepath.Join(h.ThriftIDLPath(), config.IDLFile)
mspec, err := NewModuleSpec(thriftFile, annotate, false, h)

if err != nil {
Expand Down Expand Up @@ -161,8 +151,8 @@ func (c *HTTPClientConfig) NewClientSpec(
// TChannelClientConfig represents the "config" field for a TChannel client-config.yaml
type TChannelClientConfig struct {
ClassConfigBase `yaml:",inline" json:",inline"`
Dependencies Dependencies `yaml:"dependencies,omitempty" json:"dependencies"`
Config *ClientThriftConfig `yaml:"config" json:"config" validate:"nonzero"`
Dependencies Dependencies `yaml:"dependencies,omitempty" json:"dependencies"`
Config *ClientIDLConfig `yaml:"config" json:"config" validate:"nonzero"`
}

func newTChannelClientConfig(raw []byte) (*TChannelClientConfig, error) {
Expand Down
14 changes: 7 additions & 7 deletions codegen/client_test.go
Expand Up @@ -150,7 +150,7 @@ config:
assert.Error(t, err)
assert.Equal(
t,
fmt.Sprintf("%s client config validation failed: Config.ThriftFile: zero value", clientType),
fmt.Sprintf("%s client config validation failed: Config.IDLFile: zero value", clientType),
err.Error())
}

Expand Down Expand Up @@ -273,12 +273,12 @@ func TestNewClientConfigGetHTTPClient(t *testing.T) {
Dependencies: Dependencies{
Client: []string{"a", "b"},
},
Config: &ClientThriftConfig{
Config: &ClientIDLConfig{
ExposedMethods: map[string]string{
"a": "method",
},
ThriftFileSha: "thriftFileSha",
ThriftFile: "clients/bar/bar.thrift",
IDLFileSha: "thriftFileSha",
IDLFile: "clients/bar/bar.thrift",
SidecarRouter: "sidecar",
Fixture: &Fixture{
ImportPath: "import",
Expand All @@ -302,12 +302,12 @@ func TestNewClientConfigGetTChannelClient(t *testing.T) {
Dependencies: Dependencies{
Client: []string{"a", "b"},
},
Config: &ClientThriftConfig{
Config: &ClientIDLConfig{
ExposedMethods: map[string]string{
"a": "method",
},
ThriftFileSha: "thriftFileSha",
ThriftFile: "clients/bar/bar.thrift",
IDLFileSha: "thriftFileSha",
IDLFile: "clients/bar/bar.thrift",
SidecarRouter: "sidecar",
Fixture: &Fixture{
ImportPath: "import",
Expand Down
2 changes: 1 addition & 1 deletion codegen/type_converter.go
Expand Up @@ -915,7 +915,7 @@ func (c *TypeConverter) genStructConverter(
// toField.Type.TypeCode().String(), toField.Name,
// )

// pkgName, err := h.TypePackageName(toField.Type.ThriftFile())
// pkgName, err := h.TypePackageName(toField.Type.IDLFile())
// if err != nil {
// return nil, err
// }
Expand Down
4 changes: 2 additions & 2 deletions docs/client_config_schema.json
Expand Up @@ -25,14 +25,14 @@
"config": {
"type": "object",
"properties": {
"thriftFile": {
"idlFile": {
"type": "string",
"description": "Path to client thrift file, relative to idl path",
"examples": [
"clients/contacts/contacts.thrift"
]
},
"thriftFileSha": {
"idlFileSha": {
"type": "string",
"description": "Sha of the thrift file, reserved but currently not used",
"examples": [
Expand Down
4 changes: 2 additions & 2 deletions examples/example-gateway/clients/bar/client-config.json
Expand Up @@ -2,8 +2,8 @@
"name": "bar",
"type": "http",
"config": {
"thriftFile": "clients/bar/bar.thrift",
"thriftFileSha": "{{placeholder}}",
"idlFile": "clients/bar/bar.thrift",
"idlFileSha": "{{placeholder}}",
"exposedMethods": {
"Normal": "Bar::normal",
"NormalRecur": "Bar::normalRecur",
Expand Down
4 changes: 2 additions & 2 deletions examples/example-gateway/clients/baz/client-config.yaml
Expand Up @@ -27,8 +27,8 @@ config:
TransHeadersNoReq: SimpleService::transHeadersNoReq
TransHeadersType: SimpleService::transHeadersType
URLTest: SimpleService::urlTest
thriftFile: clients/baz/baz.thrift
thriftFileSha: '{{placeholder}}'
idlFile: clients/baz/baz.thrift
idlFileSha: '{{placeholder}}'
genTestServer: true
name: baz
type: tchannel
4 changes: 2 additions & 2 deletions examples/example-gateway/clients/contacts/client-config.yaml
Expand Up @@ -7,7 +7,7 @@ config:
scenarios:
SaveContacts:
- success
thriftFile: clients/contacts/contacts.thrift
thriftFileSha: '{{placeholder}}'
idlFile: clients/contacts/contacts.thrift
idlFileSha: '{{placeholder}}'
name: contacts
type: http
Expand Up @@ -2,7 +2,7 @@ config:
exposedMethods:
EchoString: Corge::echoString
sidecarRouter: default
thriftFile: clients/corge/corge.thrift
thriftFileSha: '{{placeholder}}'
idlFile: clients/corge/corge.thrift
idlFileSha: '{{placeholder}}'
name: corge-http
type: http
4 changes: 2 additions & 2 deletions examples/example-gateway/clients/corge/client-config.yaml
Expand Up @@ -2,7 +2,7 @@ config:
exposedMethods:
EchoString: Corge::echoString
sidecarRouter: default
thriftFile: clients/corge/corge.thrift
thriftFileSha: '{{placeholder}}'
idlFile: clients/corge/corge.thrift
idlFileSha: '{{placeholder}}'
name: corge
type: tchannel
Expand Up @@ -2,7 +2,7 @@ config:
exposedMethods:
AddCredentials: GoogleNowService::addCredentials
CheckCredentials: GoogleNowService::checkCredentials
thriftFile: clients/googlenow/googlenow.thrift
thriftFileSha: '{{placeholder}}'
idlFile: clients/googlenow/googlenow.thrift
idlFileSha: '{{placeholder}}'
name: google-now
type: http
4 changes: 2 additions & 2 deletions examples/example-gateway/clients/multi/client-config.yaml
Expand Up @@ -2,7 +2,7 @@ config:
exposedMethods:
HelloA: ServiceABack::hello
HelloB: ServiceBBack::hello
thriftFile: clients/multi/multi.thrift
thriftFileSha: '{{placeholder}}'
idlFile: clients/multi/multi.thrift
idlFileSha: '{{placeholder}}'
name: multi
type: http
Expand Up @@ -2,8 +2,8 @@
"name": "withexceptions",
"type": "http",
"config": {
"thriftFile": "clients/withexceptions/withexceptions.thrift",
"thriftFileSha": "{{placeholder}}",
"idlFile": "clients/withexceptions/withexceptions.thrift",
"idlFileSha": "{{placeholder}}",
"exposedMethods": {
"Func1": "WithExceptions::Func1"
}
Expand Down

0 comments on commit c4b3be5

Please sign in to comment.