dubbo.apache.org/dubbo-go/v3@v3.1.1/protocol/grpc/config.go (about)

     1  /*
     2   * Licensed to the Apache Software Foundation (ASF) under one or more
     3   * contributor license agreements.  See the NOTICE file distributed with
     4   * this work for additional information regarding copyright ownership.
     5   * The ASF licenses this file to You under the Apache License, Version 2.0
     6   * (the "License"); you may not use this file except in compliance with
     7   * the License.  You may obtain a copy of the License at
     8   *
     9   *     http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   */
    17  
    18  package grpc
    19  
    20  import (
    21  	perrors "github.com/pkg/errors"
    22  )
    23  
    24  type (
    25  	// ServerConfig currently is empty struct,for future expansion
    26  	ServerConfig struct{}
    27  
    28  	// ClientConfig wrap client call parameters
    29  	ClientConfig struct {
    30  		// content type, more information refer by https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#requests
    31  		ContentSubType string `default:"proto" yaml:"content_sub_type" json:"content_sub_type,omitempty"`
    32  	}
    33  )
    34  
    35  // GetDefaultClientConfig return grpc client default call options
    36  func GetDefaultClientConfig() ClientConfig {
    37  	return ClientConfig{
    38  		ContentSubType: codecProto,
    39  	}
    40  }
    41  
    42  // GetDefaultServerConfig currently return empty struct,for future expansion
    43  func GetDefaultServerConfig() ServerConfig {
    44  	return ServerConfig{}
    45  }
    46  
    47  // GetClientConfig return grpc client custom call options
    48  func GetClientConfig() ClientConfig {
    49  	return ClientConfig{}
    50  }
    51  
    52  // Validate check if custom config encoding is supported in dubbo grpc
    53  func (c *ClientConfig) Validate() error {
    54  	if c.ContentSubType != codecJson && c.ContentSubType != codecProto {
    55  		return perrors.Errorf(" dubbo-go grpc codec currently only support proto态json, %s isn't supported,"+
    56  			" please check protocol content_sub_type config", c.ContentSubType)
    57  	}
    58  	return nil
    59  }
    60  
    61  // Validate currently return empty struct,for future expansion
    62  func (c *ServerConfig) Validate() error {
    63  	return nil
    64  }