Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
62dc80c9
Commit
62dc80c9
authored
Mar 09, 2016
by
Wojciech Tyczynski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix package
parent
454468f5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
51 deletions
+23
-51
generator.go
cmd/libs/go2idl/go-to-protobuf/protobuf/generator.go
+2
-15
import_tracker.go
cmd/libs/go2idl/go-to-protobuf/protobuf/import_tracker.go
+2
-0
package.go
cmd/libs/go2idl/go-to-protobuf/protobuf/package.go
+19
-36
No files found.
cmd/libs/go2idl/go-to-protobuf/protobuf/generator.go
View file @
62dc80c9
...
...
@@ -347,8 +347,6 @@ type protoField struct {
Extras
map
[
string
]
string
CommentLines
string
OptionalSet
bool
}
var
(
...
...
@@ -473,6 +471,7 @@ func protobufTagToField(tag string, field *protoField, m types.Member, t *types.
}
field
.
Tag
=
protoTag
// TODO: we are converting a Protobuf type back into an internal type, which is questionable
// TODO; Allow a way to unambiguously represent a type into two systems at the same time, like Go and Protobuf.
if
last
:=
strings
.
LastIndex
(
parts
[
0
],
"."
);
last
!=
-
1
{
prefix
:=
parts
[
0
][
:
last
]
field
.
Type
=
&
types
.
Type
{
...
...
@@ -498,7 +497,6 @@ func protobufTagToField(tag string, field *protoField, m types.Member, t *types.
}
}
}
field
.
OptionalSet
=
true
protoExtra
:=
make
(
map
[
string
]
string
)
for
i
,
extra
:=
range
parts
[
3
:
]
{
...
...
@@ -511,6 +509,7 @@ func protobufTagToField(tag string, field *protoField, m types.Member, t *types.
parts
[
0
]
=
fmt
.
Sprintf
(
"(gogoproto.%s)"
,
parts
[
0
])
protoExtra
[
parts
[
0
]]
=
parts
[
1
]
}
// TODO: Should we parse castkey and castvalue too?
}
field
.
Extras
=
protoExtra
...
...
@@ -710,18 +709,6 @@ func (ft protoIDLFileType) assemble(w io.Writer, f *generator.File) {
w
.
Write
(
f
.
Body
.
Bytes
())
}
func
isPackable
(
t
*
types
.
Type
)
bool
{
if
t
.
Kind
!=
typesKindProtobuf
{
return
false
}
switch
t
.
Name
.
Name
{
case
"int32"
,
"int64"
,
"varint"
:
return
true
default
:
return
false
}
}
func
isPrivateGoName
(
name
string
)
bool
{
if
len
(
name
)
==
0
{
return
true
...
...
cmd/libs/go2idl/go-to-protobuf/protobuf/import_tracker.go
View file @
62dc80c9
...
...
@@ -27,6 +27,8 @@ import (
//
// TODO: pay attention to the package name (instead of renaming every package).
// TODO: Figure out the best way to make names for packages that collide.
//
// TODO: Try to merge this into generator.ImportTracker (or refactor common parts).
type
ImportTracker
struct
{
pathToName
map
[
string
]
string
// forbidden names are in here. (e.g. "go" is a directory in which
...
...
cmd/libs/go2idl/go-to-protobuf/protobuf/package.go
View file @
62dc80c9
...
...
@@ -32,44 +32,37 @@ import (
func
newProtobufPackage
(
packagePath
,
packageName
string
,
generateAll
bool
,
omitFieldTypes
map
[
types
.
Name
]
struct
{})
*
protobufPackage
{
pkg
:=
&
protobufPackage
{
// The protobuf package name (foo.bar.baz)
PackageName
:
packageName
,
// A path segment relative to the GOPATH root (foo/bar/baz)
PackagePath
:
packagePath
,
GenerateAll
:
generateAll
,
OmitFieldTypes
:
omitFieldTypes
,
HeaderText
:
[]
byte
(
`
// This file was autogenerated by the command:
// $ `
+
os
.
Args
[
0
]
+
`
// Do not edit it manually!
DefaultPackage
:
generator
.
DefaultPackage
{
// The protobuf package name (foo.bar.baz)
PackageName
:
packageName
,
// A path segment relative to the GOPATH root (foo/bar/baz)
PackagePath
:
packagePath
,
HeaderText
:
[]
byte
(
`
// This file was autogenerated by go-to-protobuf. Do not edit it manually!
`
),
PackageDocumentation
:
[]
byte
(
fmt
.
Sprintf
(
`// Package %s is an autogenerated protobuf IDL.
PackageDocumentation
:
[]
byte
(
fmt
.
Sprintf
(
`// Package %s is an autogenerated protobuf IDL.
`
,
packageName
)),
},
GenerateAll
:
generateAll
,
OmitFieldTypes
:
omitFieldTypes
,
}
pkg
.
FilterFunc
=
pkg
.
filterFunc
pkg
.
GeneratorFunc
=
pkg
.
generatorFunc
return
pkg
}
// protobufPackage contains the protobuf implementation of Package.
type
protobufPackage
struct
{
// Short name of package, used in the "package xxxx" line.
PackageName
string
// Import path of the package, and the location on disk of the package.
PackagePath
string
generator
.
DefaultPackage
// If true, generate protobuf serializations for all public types.
// If false, only generate protobuf serializations for structs that
// request serialization.
GenerateAll
bool
// Emitted at the top of every file.
HeaderText
[]
byte
// Emitted only for a "doc.go" file; appended to the HeaderText for
// that file.
PackageDocumentation
[]
byte
// A list of types to filter to; if not specified all types will be included.
FilterTypes
map
[
types
.
Name
]
struct
{}
...
...
@@ -106,10 +99,7 @@ func (p *protobufPackage) ProtoTypeName() types.Name {
}
}
func
(
p
*
protobufPackage
)
Name
()
string
{
return
p
.
PackageName
}
func
(
p
*
protobufPackage
)
Path
()
string
{
return
p
.
PackagePath
}
func
(
p
*
protobufPackage
)
Filter
(
c
*
generator
.
Context
,
t
*
types
.
Type
)
bool
{
func
(
p
*
protobufPackage
)
filterFunc
(
c
*
generator
.
Context
,
t
*
types
.
Type
)
bool
{
switch
t
.
Kind
{
case
types
.
Func
,
types
.
Chan
:
return
false
...
...
@@ -175,7 +165,7 @@ func (p *protobufPackage) ExtractGeneratedType(t *ast.TypeSpec) bool {
return
true
}
func
(
p
*
protobufPackage
)
Generators
(
c
*
generator
.
Context
)
[]
generator
.
Generator
{
func
(
p
*
protobufPackage
)
generatorFunc
(
c
*
generator
.
Context
)
[]
generator
.
Generator
{
generators
:=
[]
generator
.
Generator
{}
p
.
Imports
.
AddNullable
()
...
...
@@ -194,13 +184,6 @@ func (p *protobufPackage) Generators(c *generator.Context) []generator.Generator
return
generators
}
func
(
p
*
protobufPackage
)
Header
(
filename
string
)
[]
byte
{
if
filename
==
"doc.go"
{
return
append
(
p
.
HeaderText
,
p
.
PackageDocumentation
...
)
}
return
p
.
HeaderText
}
func
(
p
*
protobufPackage
)
GoPackageName
()
string
{
return
filepath
.
Base
(
p
.
PackagePath
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment