func NewServiceBinding(service *protomodel.Service, method *descriptor.MethodDescriptorProto, rule *annotations.HttpRule, index int) error {
	binding, err := NewRESTBinding(pbinfo.FullyQualifiedType(service.TypeName, method.GetName()), rule, index)
	if err != nil {
		return fmt.Errorf("service %q: %s", service.Name, err)
	}
	service.AddBinding(binding)
	return nil
}
NewServiceBinding adds `rule` (as the `index`th binding for `method`) to the specified `service`.
package genrest
import (
	"fmt"
	"github.com/golang/protobuf/protoc-gen-go/descriptor"
	"github.com/googleapis/gapic-showcase/util/genrest/internal/pbinfo"
	"github.com/googleapis/gapic-showcase/util/genrest/protomodel"
	"google.golang.org/genproto/googleapis/api/annotations"
	"google.golang.org/protobuf/compiler/protogen"
	"google.golang.org/protobuf/proto"
	"google.golang.org/protobuf/types/descriptorpb"
)
func NewProtoModel(plugin *protogen.Plugin) (*protomodel.Model, error) {
	protoFiles := plugin.Request.GetProtoFile()
	protoModel := &protomodel.Model{
		ProtoInfo: pbinfo.Of(protoFiles),
		Services:  make([]*protomodel.Service, 0, len(protoFiles)),
	}
	generateFile := map[string]bool{}
	for _, fileName := range plugin.Request.GetFileToGenerate() {
		generateFile[fileName] = true
	}
	for _, protoFile := range protoFiles {
		if !generateFile[*protoFile.Name] {
			continue
		}
		protoPackage := *protoFile.Package
		for _, svc := range protoFile.GetService() {
			serviceModel := protoModel.AddService(NewService(protoPackage, svc))
			for _, method := range svc.GetMethod() {
				options := method.GetOptions()
				if options == nil {
					continue
				}
				eHTTP   := proto.GetExtension(method.GetOptions(), annotations.E_Http)
				http := eHTTP.(*annotations.HttpRule)
				rules := []*annotations.HttpRule{http}
				rules = append(rules, http.GetAdditionalBindings()...)
				for idxRule, oneRule := range rules {
					protoModel.AccumulateError(NewServiceBinding(serviceModel, method, oneRule, idxRule))
				}
			}
		}
	}
	return protoModel, protoModel.Error()
}
func NewService(protoPackage string, descriptor *descriptorpb.ServiceDescriptorProto) *protomodel.Service {
	service := &protomodel.Service{
		Descriptor:   descriptor,
		Name:         *descriptor.Name,
		TypeName:     pbinfo.FullyQualifiedType(protoPackage, descriptor.GetName()),
		RESTBindings: make([]*protomodel.RESTBinding, 0),
	}
	return service
}