This repository has been archived on 2020-04-27. You can view files and clone it, but cannot push or open issues or pull requests.
cmd/xorm/lang.go
Lunny Xiao 9ccdb0ebed
All checks were successful
continuous-integration/drone/push Build is passing
upgrade to xorm v1.0.1
2020-04-27 09:43:43 +08:00

67 lines
1.2 KiB
Go

// Copyright 2017 The Xorm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"io/ioutil"
"strings"
"text/template"
"xorm.io/xorm/names"
"xorm.io/xorm/schemas"
)
type LangTmpl struct {
Funcs template.FuncMap
Formater func(string) (string, error)
GenImports func([]*schemas.Table) map[string]string
}
var (
mapper = &names.SnakeMapper{}
langTmpls = map[string]LangTmpl{
"go": GoLangTmpl,
"c++": CPlusTmpl,
"objc": ObjcTmpl,
}
)
func loadConfig(f string) map[string]string {
bts, err := ioutil.ReadFile(f)
if err != nil {
return nil
}
configs := make(map[string]string)
lines := strings.Split(string(bts), "\n")
for _, line := range lines {
line = strings.TrimRight(line, "\r")
vs := strings.Split(line, "=")
if len(vs) == 2 {
configs[strings.TrimSpace(vs[0])] = strings.TrimSpace(vs[1])
}
}
return configs
}
func unTitle(src string) string {
if src == "" {
return ""
}
if len(src) == 1 {
return strings.ToLower(string(src[0]))
} else {
return strings.ToLower(string(src[0])) + src[1:]
}
}
func upTitle(src string) string {
if src == "" {
return ""
}
return strings.ToUpper(src)
}