Skip to content

Latest commit

 

History

History
75 lines (53 loc) · 1.85 KB

README.md

File metadata and controls

75 lines (53 loc) · 1.85 KB

Stencil go client

Go Reference

Stencil go client package provides a store to lookup protobuf descriptors and options to keep the protobuf descriptors upto date.

It has following features

  • Deserialize protobuf messages directly by specifying protobuf message name
  • Ability to refresh protobuf descriptors in specified intervals
  • Support to download descriptors from multiple urls

Requirements

  • go 1.16

Installation

Use go get

go get github.com/odpf/stencil/clients/go

Then import the stencil package into your own code as mentioned below

import stencil "github.com/odpf/stencil/clients/go"

Usage

Creating a client

import stencil "github.com/odpf/stencil/clients/go"

url := "http://url/to/proto/descriptorset/file"
client, err := stencil.NewClient(url, stencil.Options{})

Creating a multiURLClient

import stencil "github.com/odpf/stencil/clients/go"

urls := []string{"http://urlA", "http://urlB"}
client, err := stencil.NewMultiURLClient(urls, stencil.Options{})

Get Descriptor

import stencil "github.com/odpf/stencil/clients/go"

url := "http://url/to/proto/descriptorset/file"
client, err := stencil.NewClient(url, stencil.Options{})
if err != nil {
    return
}
desc, err := client.GetDescriptor("google.protobuf.DescriptorProto")

Parse protobuf message.

import stencil "github.com/odpf/stencil/clients/go"

url := "http://url/to/proto/descriptorset/file"
client, err := stencil.NewClient(url, stencil.Options{})
if err != nil {
    return
}
data := []byte("")
desc, err := client.Parse("google.protobuf.DescriptorProto", data)

Refer to go documentation for all available methods and options.