protobuf

package
v0.0.0-...-9c8aaae Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Copyright © 2019 hori-ryota <hori.ryota@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Example
package main

import (
	cmd "github.com/hori-ryota/go-codegen/codegen"
	"github.com/mattn/go-shellwords"
	"github.com/spf13/cobra"
)

func main() {
	input := "error protobuf -t ../internal/testdata -o ../internal/testdata/error.proto --protoPackage testdata --javaPackage com.github.horiryota.gocodegen.error.testdata --javaOuterClassName ErrorProto"

	cmd := prepareCmdWithStdout(input)
	err := cmd.Execute()
	if err != nil {
		panic(err)
	}
}

func prepareCmdWithStdout(input string) *cobra.Command {
	input += " --useStdOut"
	args, err := shellwords.Parse(input)
	if err != nil {
		panic(err)
	}
	cmd := cmd.NewRootCmd()
	cmd.SetArgs(args)
	return cmd
}
Output:

syntax = "proto3";

package testdata;
option go_package = "github.com/hori-ryota/go-codegen/codegen/error/internal/testdata";
option java_multiple_files = true;
option java_package = "com.github.horiryota.gocodegen.error.testdata";
option java_outer_classname = "ErrorProto";

message Error {
  string code = 1;
  repeated ErrorDetail details = 2;
}

message ErrorDetail {
  string code = 1;
  repeated string args = 2;
}

Index

Examples

Constants

This section is empty.

Variables

View Source
var Template = template.Must(template.New("").Parse(strings.TrimSpace(`
syntax = "proto3";

package {{.Package}};

{{- if .GoPackage}}
option go_package = "{{.GoPackage}}";
{{- end}}
{{- if .JavaPackage}}
option java_multiple_files = true;
option java_package = "{{.JavaPackage}}";
{{- end}}
{{- if .JavaOuterClassName}}
option java_outer_classname = "{{.JavaOuterClassName}}";
{{- end}}

message Error {
  string code = 1;
  repeated ErrorDetail details = 2;
}

message ErrorDetail {
  string code = 1;
  repeated string args = 2;
}
`)))

Functions

func Generate

func Generate(
	pkgInfo *loader.PackageInfo,
	protoPackage string,
	goPackage string,
	javaPackage string,
	javaOuterClassName string,
) (string, error)

func NewProtobufCmd

func NewProtobufCmd() *cobra.Command

func Run

func Run(
	targetDir string,
	outputFile string,
	protoPackage string,
	goPackage string,
	javaPackage string,
	javaOuterClassName string,
	useStdOut bool,
) error

Types

type TemplateParam

type TemplateParam struct {
	Package            string
	GoPackage          string
	JavaPackage        string
	JavaOuterClassName string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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