Beispiel #1
0
func main() {
	conf := &Config{}

	loader := multiconfig.MultiLoader(
		&multiconfig.TagLoader{},  // assign default values
		&multiconfig.FlagLoader{}, // read flag params
		&multiconfig.EnvironmentLoader{},
	)

	if err := loader.Load(conf); err != nil {
		log.Fatalf("config read err: %s", err.Error())
	}

	if err := (&multiconfig.RequiredValidator{}).Validate(conf); err != nil {
		log.Fatalf("validation err: %s", err.Error())
	}

	c := common.NewContext()
	c.Config.Schema = conf.Schema
	c.Config.Target = conf.Target

	s, err := common.Read(c.Config.Schema)
	if err != nil {
		log.Fatalf("schema read err: %s", err.Error())
	}

	s = s.Resolve(s)

	req := &common.Req{
		Schema:  s,
		Context: c,
	}
	res := &common.Res{}
	err = conf.DDL.Generate(req, res)
	if err != nil {
		log.Fatal("geneddl err: %s", err.Error())
	}

	if err := common.WriteOutput(res.Output); err != nil {
		log.Fatal("output write err: %s", err.Error())
	}

	log.Println("module created with success")
}
Beispiel #2
0
func main() {
	conf := &Config{}

	loader := multiconfig.MultiLoader(
		&multiconfig.TagLoader{},  // assign default values
		&multiconfig.FlagLoader{}, // read flag params
		&multiconfig.EnvironmentLoader{},
	)

	if err := loader.Load(conf); err != nil {
		log.Fatalf("config read err: %s", err.Error())
	}

	if err := (&multiconfig.RequiredValidator{}).Validate(conf); err != nil {
		log.Fatalf("validation err: %s", err.Error())
	}

	c := common.NewContext()
	c.Config.Schema = conf.Schema
	c.Config.Target = conf.Target

	s, err := common.Read(conf.Schema)
	if err != nil {
		log.Fatalf("schema read err: %s", err.Error())
	}

	output, err := conf.Struct.Generate(c, s)
	if err != nil {
		log.Fatal("genestruct err: %s", err.Error())
	}

	if err := common.WriteOutput(output); err != nil {
		log.Fatal("output write err: %s", err.Error())
	}

	log.Println("module created with success")
}
Beispiel #3
0
func main() {
	conf := &Config{}

	loader := multiconfig.MultiLoader(
		&multiconfig.TagLoader{},  // assign default values
		&multiconfig.FlagLoader{}, // read flag params
	)

	if err := loader.Load(conf); err != nil {
		log.Fatalf("config read err:", err.Error())
	}

	if err := (&multiconfig.RequiredValidator{}).Validate(conf); err != nil {
		log.Fatalf("validation err: %s", err.Error())
	}

	c := common.NewContext()
	c.Config.Schema = conf.Schema
	c.Config.Target = conf.Target
	c.FieldNameFunc = geneddl.GetFieldNameFunc(conf.DDL.FieldNameCase)

	s, err := common.Read(c.Config.Schema)
	if err != nil {
		log.Fatalf("schema read err: %s", err.Error())
	}

	s.Resolve(s)

	//
	// generate sql definitions
	//
	c.Config.Target = conf.Target + "db" + "/"
	output, err := conf.DDL.Generate(c, s)
	if err != nil {
		log.Fatal("geneddl err: %s", err.Error())
	}

	if err := common.WriteOutput(output); err != nil {
		log.Fatal("output write err: %s", err.Error())
	}

	//
	// generate models
	//
	c.Config.Target = conf.Target + "models" + "/"
	output, err = conf.Models.Generate(c, s)
	if err != nil {
		log.Fatalf("err while generating models", err.Error())
	}

	if err := common.WriteOutput(output); err != nil {
		log.Fatal("output write err: %s", err.Error())
	}

	//
	// generate rowsscanner
	//
	c.Config.Target = conf.Target + "models" + "/"
	output, err = conf.Rows.Generate(c, s)
	if err != nil {
		log.Fatalf("err while generating rows", err.Error())
	}

	if err := common.WriteOutput(output); err != nil {
		log.Fatal("output write err: %s", err.Error())
	}

	//
	// generate crud statements
	//
	c.Config.Target = conf.Target + "models" + "/"
	output, err = conf.Statements.Generate(c, s)
	if err != nil {
		log.Fatalf("err while generating crud statements", err.Error())
	}

	if err := common.WriteOutput(output); err != nil {
		log.Fatal("output write err: %s", err.Error())
	}

	//
	// generate errors
	//
	c.Config.Target = conf.Target + "errors" + "/"
	output, err = conf.Errors.Generate(c, s)
	if err != nil {
		log.Fatalf("err while generating errors", err.Error())
	}

	if err := common.WriteOutput(output); err != nil {
		log.Fatal("output write err: %s", err.Error())
	}

	//
	// generate main file
	//
	c.Config.Target = conf.Target + "cmd" + "/"
	output, err = conf.Mainfile.Generate(c, s)
	if err != nil {
		log.Fatalf("err while generating main file", err.Error())
	}

	if err := common.WriteOutput(output); err != nil {
		log.Fatal("output write err: %s", err.Error())
	}

	//
	// generate clients
	//
	c.Config.Target = conf.Target + "workers" + "/"
	output, err = conf.Clients.Generate(c, s)
	if err != nil {
		log.Fatalf("err while generating clients", err.Error())
	}

	if err := common.WriteOutput(output); err != nil {
		log.Fatal("output write err: %s", err.Error())
	}

	//
	// generate exported functions
	//
	c.Config.Target = conf.Target + "workers" + "/"
	output, err = conf.Functions.Generate(c, s)
	if err != nil {
		log.Fatalf("err while generating clients", err.Error())
	}

	if err := common.WriteOutput(output); err != nil {
		log.Fatal("output write err: %s", err.Error())
	}

	log.Println("module created with success")
}