known-types

command
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 20, 2024 License: MIT Imports: 9 Imported by: 0

README

Well-Known Types Example

This example shows how to use well-known types in Protocol Buffers.

Generate Go code

A proto file is under ./known. You can use well-known types by importing google/protobuf/xxx.proto.

import "google/protobuf/timestamp.proto";

Then, you can use those types as usual.

message DiffRequest {
  google.protobuf.Value     value = 1;
  google.protobuf.Timestamp start = 2;
  google.protobuf.Timestamp end   = 3;
}

Generate code.

$ protoc --go-plugin_out=. --go-plugin_opt=paths=source_relative known/known.proto

NOTE: The generated code imports packages under https://github.com/khulnasoft-lab/go-plugin/tree/main/types/known. TinyGo cannot compile packages under https://github.com/protocolbuffers/protobuf-go/tree/master/types/known.

Compile a plugin

Use TinyGo to compile the plugin to Wasm.

$ tinygo build -o plugin/plugin.wasm -scheduler=none -target=wasi --no-debug plugin/plugin.go

Run

main.go loads the above plugin.

$ go run main.go
I love Sushi
I love Tempura
Duration: 1h0m0s

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL