Files
ent/schema/field/gen/gen.go
Ariel Mashraki bd07c86b60 all: add license header to all go files
Summary:
Used addlicense to generate this:
 addlicense -c "Facebook Inc" -f license_header .

example was taken from: https://github.com/facebook/litho/blob/master/lib/soloader/BUCK

Reviewed By: alexsn

Differential Revision: D17070152

fbshipit-source-id: e7b91398d7f6181727be3400c1872ad5f28e38ed
2019-08-27 04:48:28 -07:00

57 lines
1.3 KiB
Go

// Copyright 2019-present Facebook Inc. All rights reserved.
// This source code is licensed under the Apache 2.0 license found
// in the LICENSE file in the root directory of this source tree.
// gen is a codegen cmd for generating numeric build types from template.
package main
import (
"bytes"
"go/format"
"io/ioutil"
"log"
"strings"
"text/template"
"github.com/facebookincubator/ent/schema/field"
)
func main() {
buf, err := ioutil.ReadFile("gen/numeric.tmpl")
if err != nil {
log.Fatal("reading template file:", err)
}
intTmpl := template.Must(template.New("numeric").
Funcs(template.FuncMap{"title": strings.Title, "hasPrefix": strings.HasPrefix}).
Parse(string(buf)))
b := &bytes.Buffer{}
if err := intTmpl.Execute(b, struct {
Ints, Floats []field.Type
}{
Ints: []field.Type{
field.TypeInt,
field.TypeUint,
field.TypeInt8,
field.TypeInt16,
field.TypeInt32,
field.TypeInt64,
field.TypeUint8,
field.TypeUint16,
field.TypeUint32,
field.TypeUint64,
},
Floats: []field.Type{
field.TypeFloat64,
field.TypeFloat32,
},
}); err != nil {
log.Fatal("executing template:", err)
}
if buf, err = format.Source(b.Bytes()); err != nil {
log.Fatal("formatting output:", err)
}
if err := ioutil.WriteFile("numeric.go", buf, 0644); err != nil {
log.Fatal("writing go file:", err)
}
}