Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
426 lines (419 sloc) 8.03 KB
package protoeasy
import (
"errors"
"path/filepath"
)
var (
errGoPathNotSet = errors.New("protoeasy: GOPATH not set")
defaultGoPathRelIncludes = []string{
"src/go.pedge.io/protoeasy/vendor/go.pedge.io/pb/proto",
}
defaultGoModifierOptions = mergeStringStringMaps(
newGoModifierOptions(
"google/protobuf",
[]string{
"api.proto",
"field_mask.proto",
"source_context.proto",
"type.proto",
},
"go.pedge.io/pb/go/google/protobuf",
),
newGoModifierOptions(
"google/protobuf",
[]string{
"any.proto",
},
"github.com/golang/protobuf/ptypes/any",
),
newGoModifierOptions(
"google/protobuf",
[]string{
"duration.proto",
},
"github.com/golang/protobuf/ptypes/duration",
),
newGoModifierOptions(
"google/protobuf",
[]string{
"empty.proto",
},
"github.com/golang/protobuf/ptypes/empty",
),
newGoModifierOptions(
"google/protobuf",
[]string{
"struct.proto",
},
"github.com/golang/protobuf/ptypes/struct",
),
newGoModifierOptions(
"google/protobuf",
[]string{
"timestamp.proto",
},
"github.com/golang/protobuf/ptypes/timestamp",
),
newGoModifierOptions(
"google/protobuf",
[]string{
"wrappers.proto",
},
"github.com/golang/protobuf/ptypes/wrappers",
),
newGoModifierOptions(
"google/protobuf",
[]string{
"descriptor.proto",
},
"github.com/golang/protobuf/protoc-gen-go/descriptor",
),
newGoModifierOptions(
"google/api",
[]string{
"annotations.proto",
"http.proto",
},
"google.golang.org/genproto/googleapis/api/annotations",
),
newGoModifierOptions(
"google/api",
[]string{
"label.proto",
"monitored_resource.proto",
},
"go.pedge.io/pb/go/google/api",
),
newGoModifierOptions(
"google/datastore/v1beta3",
[]string{
"datastore.proto",
"entity.proto",
"query.proto",
},
"go.pedge.io/pb/go/google/datastore/v1beta3",
),
newGoModifierOptions(
"google/devtools/cloudtrace/v1",
[]string{
"trace.proto",
},
"go.pedge.io/pb/go/google/devtools/cloudtrace/v1",
),
newGoModifierOptions(
"google/example/library/v1",
[]string{
"library.proto",
},
"go.pedge.io/pb/go/google/example/library/v1",
),
newGoModifierOptions(
"google/iam/v1",
[]string{
"iam_policy.proto",
"policy.proto",
},
"go.pedge.io/pb/go/google/iam/v1",
),
newGoModifierOptions(
"google/logging/type",
[]string{
"http_request.proto",
"log_severity.proto",
},
"go.pedge.io/pb/go/google/logging/type",
),
newGoModifierOptions(
"google/logging/v2",
[]string{
"log_entry.proto",
"logging.proto",
"logging_config.proto",
"logging_metrics.proto",
},
"go.pedge.io/pb/go/google/logging/v2",
),
newGoModifierOptions(
"google/longrunning",
[]string{
"operations.proto",
},
"go.pedge.io/pb/go/google/longrunning",
),
newGoModifierOptions(
"google/pubsub/v1",
[]string{
"pubsub.proto",
},
"go.pedge.io/pb/go/google/pubsub/v1",
),
newGoModifierOptions(
"google/pubsub/v1beta2",
[]string{
"pubsub.proto",
},
"go.pedge.io/pb/go/google/pubsub/v1beta2",
),
newGoModifierOptions(
"google/rpc",
[]string{
"code.proto",
"error_details.proto",
"status.proto",
},
"go.pedge.io/pb/go/google/rpc",
),
newGoModifierOptions(
"google/type",
[]string{
"color.proto",
"date.proto",
"dayofweek.proto",
"latlng.proto",
"money.proto",
"timeofday.proto",
},
"go.pedge.io/pb/go/google/type",
),
newGoModifierOptions(
"pb/common",
[]string{
"common.proto",
},
"go.pedge.io/pb/go/pb/common",
),
newGoModifierOptions(
"pb/geo",
[]string{
"geo.gen.proto",
"geo.proto",
},
"go.pedge.io/pb/go/pb/geo",
),
newGoModifierOptions(
"pb/money",
[]string{
"money.gen.proto",
"money.proto",
},
"go.pedge.io/pb/go/pb/money",
),
newGoModifierOptions(
"pb/net",
[]string{
"net.proto",
},
"go.pedge.io/pb/go/pb/net",
),
newGoModifierOptions(
"pb/phone",
[]string{
"phone.proto",
},
"go.pedge.io/pb/go/pb/phone",
),
newGoModifierOptions(
"pb/time",
[]string{
"time.proto",
},
"go.pedge.io/pb/go/pb/time",
),
)
defaultGogoModifierOptions = mergeStringStringMaps(
newGoModifierOptions(
"google/protobuf",
[]string{
"api.proto",
"source_context.proto",
"type.proto",
},
"go.pedge.io/pb/gogo/google/protobuf",
),
newGoModifierOptions(
"google/protobuf",
[]string{
"any.proto",
"duration.proto",
"empty.proto",
"field_mask.proto",
"struct.proto",
"timestamp.proto",
"wrappers.proto",
},
"github.com/gogo/protobuf/types",
),
newGoModifierOptions(
"google/protobuf",
[]string{
"descriptor.proto",
},
"github.com/gogo/protobuf/protoc-gen-gogo/descriptor",
),
newGoModifierOptions(
"google/api",
[]string{
"annotations.proto",
"http.proto",
},
"google.golang.org/genproto/googleapis/api/annotations",
),
newGoModifierOptions(
"google/api",
[]string{
"label.proto",
"monitored_resource.proto",
},
"go.pedge.io/pb/gogo/google/api",
),
newGoModifierOptions(
"google/datastore/v1beta3",
[]string{
"datastore.proto",
"entity.proto",
"query.proto",
},
"go.pedge.io/pb/gogo/google/datastore/v1beta3",
),
newGoModifierOptions(
"google/devtools/cloudtrace/v1",
[]string{
"trace.proto",
},
"go.pedge.io/pb/gogo/google/devtools/cloudtrace/v1",
),
newGoModifierOptions(
"google/example/library/v1",
[]string{
"library.proto",
},
"go.pedge.io/pb/gogo/google/example/library/v1",
),
newGoModifierOptions(
"google/iam/v1",
[]string{
"iam_policy.proto",
"policy.proto",
},
"go.pedge.io/pb/gogo/google/iam/v1",
),
newGoModifierOptions(
"google/logging/type",
[]string{
"http_request.proto",
"log_severity.proto",
},
"go.pedge.io/pb/gogo/google/logging/type",
),
newGoModifierOptions(
"google/logging/v2",
[]string{
"log_entry.proto",
"logging.proto",
"logging_config.proto",
"logging_metrics.proto",
},
"go.pedge.io/pb/gogo/google/logging/v2",
),
newGoModifierOptions(
"google/longrunning",
[]string{
"operations.proto",
},
"go.pedge.io/pb/gogo/google/longrunning",
),
newGoModifierOptions(
"google/pubsub/v1",
[]string{
"pubsub.proto",
},
"go.pedge.io/pb/gogo/google/pubsub/v1",
),
newGoModifierOptions(
"google/pubsub/v1beta2",
[]string{
"pubsub.proto",
},
"go.pedge.io/pb/gogo/google/pubsub/v1beta2",
),
newGoModifierOptions(
"google/rpc",
[]string{
"code.proto",
"error_details.proto",
"status.proto",
},
"go.pedge.io/pb/gogo/google/rpc",
),
newGoModifierOptions(
"google/type",
[]string{
"color.proto",
"date.proto",
"dayofweek.proto",
"latlng.proto",
"money.proto",
"timeofday.proto",
},
"go.pedge.io/pb/gogo/google/type",
),
newGoModifierOptions(
"pb/common",
[]string{
"common.proto",
},
"go.pedge.io/pb/gogo/pb/common",
),
newGoModifierOptions(
"pb/geo",
[]string{
"geo.gen.proto",
"geo.proto",
},
"go.pedge.io/pb/gogo/pb/geo",
),
newGoModifierOptions(
"pb/money",
[]string{
"money.gen.proto",
"money.proto",
},
"go.pedge.io/pb/gogo/pb/money",
),
newGoModifierOptions(
"pb/net",
[]string{
"net.proto",
},
"go.pedge.io/pb/gogo/pb/net",
),
newGoModifierOptions(
"pb/phone",
[]string{
"phone.proto",
},
"go.pedge.io/pb/gogo/pb/phone",
),
newGoModifierOptions(
"pb/time",
[]string{
"time.proto",
},
"go.pedge.io/pb/gogo/pb/time",
),
newGoModifierOptions(
"gogoproto",
[]string{
"gogo.proto",
},
"github.com/gogo/protobuf/gogoproto",
),
)
)
func newGoModifierOptions(dir string, files []string, goPackage string) map[string]string {
m := make(map[string]string)
for _, file := range files {
m[filepath.Join(dir, file)] = goPackage
}
return m
}