You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
808 B
Go
49 lines
808 B
Go
package gogen
|
|
|
|
import (
|
|
"bytes"
|
|
"text/template"
|
|
|
|
"zero/tools/goctl/api/spec"
|
|
"zero/tools/goctl/api/util"
|
|
)
|
|
|
|
const (
|
|
configFile = "config.go"
|
|
configTemplate = `package config
|
|
|
|
import (
|
|
"zero/ngin"
|
|
{{.authImport}}
|
|
)
|
|
|
|
type Config struct {
|
|
ngin.NgConf
|
|
}
|
|
`
|
|
)
|
|
|
|
func genConfig(dir string, api *spec.ApiSpec) error {
|
|
fp, created, err := util.MaybeCreateFile(dir, configDir, configFile)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !created {
|
|
return nil
|
|
}
|
|
defer fp.Close()
|
|
|
|
var authImportStr = ""
|
|
t := template.Must(template.New("configTemplate").Parse(configTemplate))
|
|
buffer := new(bytes.Buffer)
|
|
err = t.Execute(buffer, map[string]string{
|
|
"authImport": authImportStr,
|
|
})
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
formatCode := formatCode(buffer.String())
|
|
_, err = fp.WriteString(formatCode)
|
|
return err
|
|
}
|