feat: use go:embed to embed templates (#1756)
This commit is contained in:
@@ -3,6 +3,7 @@ package javagen
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
_ "embed"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -18,54 +19,19 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
componentTemplate = `// Code generated by goctl. DO NOT EDIT.
|
||||
package com.xhb.logic.http.packet.{{.packet}}.model;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
{{.imports}}
|
||||
|
||||
public class {{.className}} extends {{.superClassName}} {
|
||||
|
||||
{{.properties}}
|
||||
{{if .HasProperty}}
|
||||
|
||||
public {{.className}}() {
|
||||
}
|
||||
|
||||
public {{.className}}({{.params}}) {
|
||||
{{.constructorSetter}}
|
||||
}
|
||||
{{end}}
|
||||
|
||||
{{.getSet}}
|
||||
}
|
||||
`
|
||||
getSetTemplate = `
|
||||
{{.indent}}{{.decorator}}
|
||||
{{.indent}}public {{.returnType}} get{{.property}}() {
|
||||
{{.indent}} return this.{{.tagValue}};
|
||||
{{.indent}}}
|
||||
|
||||
{{.indent}}public void set{{.property}}({{.type}} {{.propertyValue}}) {
|
||||
{{.indent}} this.{{.tagValue}} = {{.propertyValue}};
|
||||
{{.indent}}}
|
||||
`
|
||||
|
||||
boolTemplate = `
|
||||
{{.indent}}{{.decorator}}
|
||||
{{.indent}}public {{.returnType}} is{{.property}}() {
|
||||
{{.indent}} return this.{{.tagValue}};
|
||||
{{.indent}}}
|
||||
|
||||
{{.indent}}public void set{{.property}}({{.type}} {{.propertyValue}}) {
|
||||
{{.indent}} this.{{.tagValue}} = {{.propertyValue}};
|
||||
{{.indent}}}
|
||||
`
|
||||
httpResponseData = "import com.xhb.core.response.HttpResponseData;"
|
||||
httpData = "import com.xhb.core.packet.HttpData;"
|
||||
)
|
||||
|
||||
var (
|
||||
//go:embed component.tpl
|
||||
componentTemplate string
|
||||
//go:embed getset.tpl
|
||||
getSetTemplate string
|
||||
//go:embed bool.tpl
|
||||
boolTemplate string
|
||||
)
|
||||
|
||||
type componentsContext struct {
|
||||
api *spec.ApiSpec
|
||||
requestTypes []spec.Type
|
||||
|
||||
Reference in New Issue
Block a user