Rename from pbinfo to Svcdef
This commit is contained in:
Родитель
1c0a5910c7
Коммит
79ecc77422
|
@ -1,4 +1,4 @@
|
|||
package pbinfo
|
||||
package svcdef
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -11,13 +11,13 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// ConsolidateHTTP accepts a Catalog and the io.Readers for the proto files
|
||||
// comprising the definition. It modifies the Catalog so that HTTPBindings and
|
||||
// ConsolidateHTTP accepts a SvcDef and the io.Readers for the proto files
|
||||
// comprising the definition. It modifies the SvcDef so that HTTPBindings and
|
||||
// their associated HTTPParamters are added to each ServiceMethod. After this,
|
||||
// each `HTTPBinding` will have a populated list of all the http parameters
|
||||
// that that binding requires, where that parameter should be located, and the
|
||||
// type of each parameter.
|
||||
func ConsolidateHTTP(cat *Catalog, protoFiles []io.Reader) error {
|
||||
func ConsolidateHTTP(sd *Svcdef, protoFiles []io.Reader) error {
|
||||
for _, pfile := range protoFiles {
|
||||
lex := svcparse.NewSvcLexer(pfile)
|
||||
protosvc, err := svcparse.ParseService(lex)
|
||||
|
@ -30,7 +30,7 @@ func ConsolidateHTTP(cat *Catalog, protoFiles []io.Reader) error {
|
|||
return errors.Wrap(err, "error while parsing http options for the service definition")
|
||||
}
|
||||
}
|
||||
assembleHTTPParams(cat.Service, protosvc)
|
||||
assembleHTTPParams(sd.Service, protosvc)
|
||||
}
|
||||
return nil
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package pbinfo
|
||||
package svcdef
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
@ -84,16 +84,15 @@ service Map {
|
|||
}
|
||||
}`
|
||||
// From code, build our SvcDef
|
||||
cat, err := New([]io.Reader{strings.NewReader(goCode)}, []io.Reader{strings.NewReader(protoCode)})
|
||||
sd, err := New([]io.Reader{strings.NewReader(goCode)}, []io.Reader{strings.NewReader(protoCode)})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_ = cat
|
||||
|
||||
tmap := newTypeMap(cat)
|
||||
tmap := newTypeMap(sd)
|
||||
|
||||
rq := cat.Service.Methods[0].RequestType
|
||||
bind := cat.Service.Methods[0].Bindings[0]
|
||||
rq := sd.Service.Methods[0].RequestType
|
||||
bind := sd.Service.Methods[0].Bindings[0]
|
||||
if len(bind.Params) != len(tmap["Thing"].Message.Fields) {
|
||||
t.Fatalf(
|
||||
"Number of http parameters '%v' differs from number of fields on message '%v'",
|
|
@ -1,6 +1,6 @@
|
|||
package pbinfo
|
||||
package svcdef
|
||||
|
||||
// After the initial creation of Catalog, each FieldType will have it's name
|
||||
// After the initial creation of Svcdef, each FieldType will have it's name
|
||||
// set to the name of the type that it represents, but it won't have a pointer
|
||||
// to the full instance of the type with that name. Type resolution is the
|
||||
// process of taking the name of each FieldType, then searching for the
|
||||
|
@ -12,17 +12,17 @@ type typeBox struct {
|
|||
Enum *Enum
|
||||
}
|
||||
|
||||
// resolveTypes accepts a pointer to a Catalog and modifies that Catalog, and
|
||||
// resolveTypes accepts a pointer to a Svcdef and modifies that Svcdef, and
|
||||
// it's child structs, in place.
|
||||
func resolveTypes(cat *Catalog) {
|
||||
tmap := newTypeMap(cat)
|
||||
for _, m := range cat.Messages {
|
||||
func resolveTypes(sd *Svcdef) {
|
||||
tmap := newTypeMap(sd)
|
||||
for _, m := range sd.Messages {
|
||||
for _, f := range m.Fields {
|
||||
setType(f.Type, tmap)
|
||||
}
|
||||
}
|
||||
if cat.Service != nil {
|
||||
for _, m := range cat.Service.Methods {
|
||||
if sd.Service != nil {
|
||||
for _, m := range sd.Service.Methods {
|
||||
setType(m.RequestType, tmap)
|
||||
setType(m.ResponseType, tmap)
|
||||
}
|
||||
|
@ -49,12 +49,12 @@ func setType(f *FieldType, tmap map[string]typeBox) {
|
|||
}
|
||||
|
||||
// newTypeMap returns a map from
|
||||
func newTypeMap(cat *Catalog) map[string]typeBox {
|
||||
func newTypeMap(sd *Svcdef) map[string]typeBox {
|
||||
rv := make(map[string]typeBox)
|
||||
for _, m := range cat.Messages {
|
||||
for _, m := range sd.Messages {
|
||||
rv[m.Name] = typeBox{Message: m}
|
||||
}
|
||||
for _, e := range cat.Enums {
|
||||
for _, e := range sd.Enums {
|
||||
rv[e.Name] = typeBox{Enum: e}
|
||||
}
|
||||
return rv
|
|
@ -1,4 +1,4 @@
|
|||
package pbinfo
|
||||
package svcdef
|
||||
|
||||
// consider renaming to census, pbregistry, or just to "essence"
|
||||
|
||||
|
@ -12,7 +12,7 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type Catalog struct {
|
||||
type Svcdef struct {
|
||||
// PkgName will be the pacakge name of the go file(s) analyzed. So if a
|
||||
// Go file contained "package authz", then PkgName will be "authz". If
|
||||
// multiple Go files are analyzed, it will be the package name of the last
|
||||
|
@ -20,7 +20,7 @@ type Catalog struct {
|
|||
PkgName string
|
||||
Messages []*Message
|
||||
Enums []*Enum
|
||||
// Service contains the sole service for this Catalog
|
||||
// Service contains the sole service for this Svcdef
|
||||
Service *Service
|
||||
}
|
||||
|
||||
|
@ -112,14 +112,14 @@ func retrieveTypeSpecs(f *ast.File) ([]*ast.TypeSpec, error) {
|
|||
return rv, nil
|
||||
}
|
||||
|
||||
func New(goFiles []io.Reader, protoFiles []io.Reader) (*Catalog, error) {
|
||||
rv := Catalog{}
|
||||
func New(goFiles []io.Reader, protoFiles []io.Reader) (*Svcdef, error) {
|
||||
rv := Svcdef{}
|
||||
|
||||
for _, gofile := range goFiles {
|
||||
fset := token.NewFileSet()
|
||||
fileAst, err := parser.ParseFile(fset, "", gofile, parser.ParseComments)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "couldn't parse go file to create catalog")
|
||||
return nil, errors.Wrap(err, "couldn't parse go file to create Svcdef")
|
||||
}
|
||||
|
||||
typespecs, _ := retrieveTypeSpecs(fileAst)
|
|
@ -1,4 +1,4 @@
|
|||
package pbinfo
|
||||
package svcdef
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
@ -17,12 +17,12 @@ func TestNewCatalog(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cat, err := New([]io.Reader{gf}, []io.Reader{pf})
|
||||
sd, err := New([]io.Reader{gf}, []io.Reader{pf})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if cat == nil {
|
||||
t.Fatal("returned catalog is nil!")
|
||||
if sd == nil {
|
||||
t.Fatal("returned SvcDef is nil!")
|
||||
}
|
||||
|
||||
return
|
||||
|
@ -48,15 +48,11 @@ type NestedTypeRequest struct {
|
|||
B []*NestedMessageB
|
||||
C EnumType
|
||||
}`
|
||||
cat, err := New([]io.Reader{strings.NewReader(caseCode)}, nil)
|
||||
sd, err := New([]io.Reader{strings.NewReader(caseCode)}, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
//sp := spew.ConfigState{
|
||||
//Indent: " ",
|
||||
//}
|
||||
tmap := newTypeMap(cat)
|
||||
//sp.Dump(cat)
|
||||
tmap := newTypeMap(sd)
|
||||
|
||||
var cases = []struct {
|
||||
name, fieldname, typename string
|
||||
|
@ -115,11 +111,11 @@ type MapNestedMsg struct {
|
|||
Beta map[int64]*NestedMessageC
|
||||
}
|
||||
`
|
||||
cat, err := New([]io.Reader{strings.NewReader(caseCode)}, nil)
|
||||
sd, err := New([]io.Reader{strings.NewReader(caseCode)}, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tmap := newTypeMap(cat)
|
||||
tmap := newTypeMap(sd)
|
||||
|
||||
expected, ok := tmap["MapNestedMsg"]
|
||||
if !ok {
|
Загрузка…
Ссылка в новой задаче