Generate Structs Reference

Use Kitex tool to generate structs reference to solve public structs problem.

Usage Scenarios

For kitex_gen structs generated by the same IDL, if they are placed in different git repo, the type will be inconsistent. Some business teams will have an independent structs git repo for the public IDL to store these generated codes. The kitex tool can directly generate references to the remote repo for a specific IDL without actually generating a struct in the code generation stage, thereby solving the situation of type inconsistency.

Practice

First make sure:

  • The kitex tool version is not lower than v0.4.4
  • thriftgo version not lower than v0.2.4

Create a file called idl-ref.yml to configure the remote references you want to use for a particular IDL:

 ref:
  idl/base.thrift: "github.com/xxxx/public_repo/base"
  idl/public/item.thrift: "github.com/xxxx/public_repo/item"

After the kitex command is normally executed in the directory with idl-ref.yml, the specified IDL will not generate a complete serialization and deserialization code after execution, but will generate a remote reference to the structs, thereby solving the common Library structure conflict problem. An example of the generated codes is as follows:

// Code generated by thriftgo (0.2.4). DO NOT EDIT.

package base

import (
    base "github.com/xxxx/public_repo/base"
)

type Base = base.Base

var NewBase = base. NewBase

type BaseResp = base. BaseResp

var NewBaseResp = base. NewBaseResp

const MY_CONST = base.MY_CONST

var MAP_CONST = base.MAP_CONST


Last modified July 3, 2023 : Update response.md (604692d)