gmfs

package module
v0.0.0-...-1d8482b Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2022 License: MIT Imports: 8 Imported by: 0

README

gmfs

Generate protobuf message from go struct.

Installing

go install github.com/google/wire/cmd/gsmf@latest

Usage

$ gmfs -h
usage: gstm [-s] GO_FILES
  -s string
    	Regexp match struct name. (default ".*")
$ cat example.go 
package testdata

import "time"

func P() {}

// Item Comment
type Item struct {
        ItemId    int // ItemId Comment
        Name      string
        Duration  time.Duration
        CreatedAt time.Time
}

type TemplateData struct {
        Arr   []string
        Items []*Item
        Map   map[string]*Item
}

$ gmfs example.go             
// Code generated by gstm.
// source: example.go.

// Item Comment
message Item {
        // ItemId Comment
        int64 item_id = 1;

        string name = 2;

        Duration duration = 3;

        google.protobuf.Timestamp created_at = 4;
}

message TemplateData {

        repeated string arr = 1;

        repeated Item items = 2;

        map<string,Item> map = 3;
}%

Documentation

Overview

Package gmfs provides a method to convert specified struct from reader and write to given writer.

Index

Examples

Constants

This section is empty.

Variables

View Source
var TypInt = fmt.Sprintf("int%d", 32<<(^uint(0)>>63))

Functions

func GenMsg

func GenMsg(r io.Reader, w io.Writer, exp regexp.Regexp) error
Example
package main

import (
	"bytes"
	"os"
	"regexp"

	"github.com/Dokiys/codemates/gmfs"
)

func main() {
	src := `
package example

import (
	"fmt"
	"time"
)

func (i *Item) P() {}

// Item Comment 1
/*
	Item Comment 1
*/
// Item Comment 1
type Item struct {
	// Item ItemId Comment 3

	// Item ItemId Comment 2
	ItemId    int // Item ItemId Comment 1
	Name      string
	Duration  time.Duration
	CreatedAt time.Time
}

type TemplateData struct {
	Arr   []string
	Items []*Item
	Map1  map[string]*Item

	// Unsupported
	//TdArr [][]string
	//Map2 map[string][]*Item
	//Map3 []map[string]*Item
	//Map4 []map[*Item]string
	//Map5 []map[string][]*Item
}
`
	r := bytes.NewReader([]byte(src))

	exp, _ := regexp.Compile(".*")
	_ = gmfs.GenMsg(r, os.Stdout, *exp)
}
Output:


// Item Comment 1
/*
	Item Comment 1
*/
// Item Comment 1
message Item {
	// Item ItemId Comment 1
	int64 item_id = 1;

	string name = 2;

	Duration duration = 3;

	google.protobuf.Timestamp created_at = 4;
}

message TemplateData {

	repeated string arr = 1;

	repeated Item items = 2;

	map<string,Item> map1 = 3;
}

func RegisterValidateFunc

func RegisterValidateFunc(f ValidateFunc)

Types

type ValidateFunc

type ValidateFunc = func(field *ast.Field) string

Jump to

Keyboard shortcuts

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