feat: use go:embed to embed templates (#1756)
This commit is contained in:
@@ -2,6 +2,7 @@ package javagen
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"strings"
|
||||
"text/template"
|
||||
@@ -12,32 +13,8 @@ import (
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util"
|
||||
)
|
||||
|
||||
const packetTemplate = `package com.xhb.logic.http.packet.{{.packet}};
|
||||
|
||||
import com.xhb.core.packet.HttpPacket;
|
||||
import com.xhb.core.network.HttpRequestClient;
|
||||
{{.imports}}
|
||||
|
||||
{{.doc}}
|
||||
public class {{.packetName}} extends HttpPacket<{{.responseType}}> {
|
||||
{{.paramsDeclaration}}
|
||||
|
||||
public {{.packetName}}({{.params}}{{if .HasRequestBody}}{{.requestType}} request{{end}}) {
|
||||
{{if .HasRequestBody}}super(request);{{else}}super(EmptyRequest.instance);{{end}}
|
||||
{{if .HasRequestBody}}this.request = request;{{end}}{{.paramsSetter}}
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpRequestClient.Method requestMethod() {
|
||||
return HttpRequestClient.Method.{{.method}};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String requestUri() {
|
||||
return {{.uri}};
|
||||
}
|
||||
}
|
||||
`
|
||||
//go:embed packet.tpl
|
||||
var packetTemplate string
|
||||
|
||||
func genPacket(dir, packetName string, api *spec.ApiSpec) error {
|
||||
for _, route := range api.Service.Routes() {
|
||||
|
||||
Reference in New Issue
Block a user