Code optimized (#523)
* optimized markdown generator * optimized markdown generator * optimized markdown generator * add more comment * add comment * add comment * add comments for rpc tool * add comments for model tool * add comments for model tool * add comments for model tool * add comments for config tool * add comments for config tool * add comments * add comments * add comments * add comments * add comment * remove rpc main head info * add comment * optimized Co-authored-by: anqiansong <anqiansong@xiaoheiban.cn>
This commit is contained in:
@@ -2,6 +2,7 @@ package parser
|
||||
|
||||
import "github.com/emicklei/proto"
|
||||
|
||||
// GetComment returns content with prefix //
|
||||
func GetComment(comment *proto.Comment) string {
|
||||
if comment == nil {
|
||||
return ""
|
||||
|
||||
@@ -2,6 +2,7 @@ package parser
|
||||
|
||||
import "github.com/emicklei/proto"
|
||||
|
||||
// Import embeds proto.Import
|
||||
type Import struct {
|
||||
*proto.Import
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package parser
|
||||
|
||||
import pr "github.com/emicklei/proto"
|
||||
import "github.com/emicklei/proto"
|
||||
|
||||
// Message embeds proto.Message
|
||||
type Message struct {
|
||||
*pr.Message
|
||||
*proto.Message
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package parser
|
||||
|
||||
import "github.com/emicklei/proto"
|
||||
|
||||
// Option embeds proto.Option
|
||||
type Option struct {
|
||||
*proto.Option
|
||||
}
|
||||
|
||||
@@ -14,14 +14,18 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
defaultProtoParser struct{}
|
||||
// DefaultProtoParser types a empty struct
|
||||
DefaultProtoParser struct{}
|
||||
)
|
||||
|
||||
func NewDefaultProtoParser() *defaultProtoParser {
|
||||
return &defaultProtoParser{}
|
||||
// NewDefaultProtoParser creates a new instance
|
||||
func NewDefaultProtoParser() *DefaultProtoParser {
|
||||
return &DefaultProtoParser{}
|
||||
}
|
||||
|
||||
func (p *defaultProtoParser) Parse(src string) (Proto, error) {
|
||||
// Parse provides to parse the proto file into a golang structure,
|
||||
// which is convenient for subsequent rpc generation and use
|
||||
func (p *DefaultProtoParser) Parse(src string) (Proto, error) {
|
||||
var ret Proto
|
||||
|
||||
abs, err := filepath.Abs(src)
|
||||
@@ -101,7 +105,7 @@ func (p *defaultProtoParser) Parse(src string) (Proto, error) {
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
// see google.golang.org/protobuf@v1.25.0/internal/strs/strings.go:71
|
||||
// GoSanitized copy from protobuf, for more information, please see google.golang.org/protobuf@v1.25.0/internal/strs/strings.go:71
|
||||
func GoSanitized(s string) string {
|
||||
// Sanitize the input to the set of valid characters,
|
||||
// which must be '_' or be in the Unicode L or N categories.
|
||||
@@ -121,7 +125,7 @@ func GoSanitized(s string) string {
|
||||
return s
|
||||
}
|
||||
|
||||
// copy from github.com/golang/protobuf@v1.4.2/protoc-gen-go/generator/generator.go:2648
|
||||
// CamelCase copy from protobuf, for more information, please see github.com/golang/protobuf@v1.4.2/protoc-gen-go/generator/generator.go:2648
|
||||
func CamelCase(s string) string {
|
||||
if s == "" {
|
||||
return ""
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package parser
|
||||
|
||||
// Proto describes a proto file,
|
||||
type Proto struct {
|
||||
Src string
|
||||
Name string
|
||||
|
||||
@@ -2,6 +2,7 @@ package parser
|
||||
|
||||
import "github.com/emicklei/proto"
|
||||
|
||||
// RPC embeds proto.RPC
|
||||
type RPC struct {
|
||||
*proto.RPC
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package parser
|
||||
|
||||
import "github.com/emicklei/proto"
|
||||
|
||||
// Service describes the rpc service, which is the relevant
|
||||
// content after the translation of the proto file
|
||||
type Service struct {
|
||||
*proto.Service
|
||||
RPC []*RPC
|
||||
|
||||
Reference in New Issue
Block a user