Add templateDir variable

This commit is contained in:
Manfred Touron 2016-12-15 16:25:44 +01:00
parent 8e2be0f866
commit f9e191c6a4
No known key found for this signature in database
GPG Key ID: 9CCF47DF1FD978A1
2 changed files with 41 additions and 33 deletions

View File

@ -18,6 +18,7 @@ type GenericTemplateBasedEncoder struct {
service *descriptor.ServiceDescriptorProto service *descriptor.ServiceDescriptorProto
file *descriptor.FileDescriptorProto file *descriptor.FileDescriptorProto
debug bool debug bool
destinationDir string
} }
type Ast struct { type Ast struct {
@ -27,6 +28,7 @@ type Ast struct {
GoPWD string `json:"go-pwd,omitempty"` GoPWD string `json:"go-pwd,omitempty"`
PWD string `json:"pwd"` PWD string `json:"pwd"`
Debug bool `json:"debug"` Debug bool `json:"debug"`
DestinationDir string `json:"destination-dir"`
File *descriptor.FileDescriptorProto `json:"file"` File *descriptor.FileDescriptorProto `json:"file"`
RawFilename string `json:"raw-filename"` RawFilename string `json:"raw-filename"`
Filename string `json:"filename"` Filename string `json:"filename"`
@ -35,12 +37,13 @@ type Ast struct {
Environment []string `json:"environment"` Environment []string `json:"environment"`
} }
func NewGenericTemplateBasedEncoder(templateDir string, service *descriptor.ServiceDescriptorProto, file *descriptor.FileDescriptorProto, debug bool) (e *GenericTemplateBasedEncoder) { func NewGenericTemplateBasedEncoder(templateDir string, service *descriptor.ServiceDescriptorProto, file *descriptor.FileDescriptorProto, debug bool, destinationDir string) (e *GenericTemplateBasedEncoder) {
e = &GenericTemplateBasedEncoder{ e = &GenericTemplateBasedEncoder{
service: service, service: service,
file: file, file: file,
templateDir: templateDir, templateDir: templateDir,
debug: debug, debug: debug,
destinationDir: destinationDir,
} }
if debug { if debug {
@ -95,6 +98,7 @@ func (e *GenericTemplateBasedEncoder) genAst(templateFilename string) (*Ast, err
GoPWD: goPwd, GoPWD: goPwd,
File: e.file, File: e.file,
TemplateDir: e.templateDir, TemplateDir: e.templateDir,
DestinationDir: e.destinationDir,
RawFilename: templateFilename, RawFilename: templateFilename,
Filename: "", Filename: "",
Environment: os.Environ(), Environment: os.Environ(),

View File

@ -30,6 +30,7 @@ func main() {
// Parse parameters // Parse parameters
templateDir := "./templates" templateDir := "./templates"
destinationDir := "."
debug := false debug := false
if parameter := g.Request.GetParameter(); parameter != "" { if parameter := g.Request.GetParameter(); parameter != "" {
for _, param := range strings.Split(parameter, ",") { for _, param := range strings.Split(parameter, ",") {
@ -42,6 +43,9 @@ func main() {
case "template_dir": case "template_dir":
templateDir = parts[1] templateDir = parts[1]
break break
case "destination_dir":
destinationDir = parts[1]
break
case "debug": case "debug":
switch strings.ToLower(parts[1]) { switch strings.ToLower(parts[1]) {
case "true", "t": case "true", "t":
@ -60,7 +64,7 @@ func main() {
// Generate the encoders // Generate the encoders
for _, file := range g.Request.GetProtoFile() { for _, file := range g.Request.GetProtoFile() {
for _, service := range file.GetService() { for _, service := range file.GetService() {
encoder := NewGenericTemplateBasedEncoder(templateDir, service, file, debug) encoder := NewGenericTemplateBasedEncoder(templateDir, service, file, debug, destinationDir)
g.Response.File = append(g.Response.File, encoder.Files()...) g.Response.File = append(g.Response.File, encoder.Files()...)
} }
} }