Exemple #1
0
func (m Model) AddModel(name string) {
	dir, _ := os.Getwd()
	f := strings.Join([]string{dir, "settings.json"}, "/")
	config := config.Load_config(f)
	db := configConnect(config)
	mt := ModelType{connection{db, config.DB.Type}, name, []Field{}}
	m[name] = &mt
}
Exemple #2
0
func NewModel(name string) Model {
	m := make(map[string]*ModelType)
	dir, _ := os.Getwd()
	f := strings.Join([]string{dir, "settings.json"}, "/")
	config := config.Load_config(f)
	db := configConnect(config)
	mt := ModelType{connection{db, config.DB.Type}, name, []Field{}}
	m[name] = &mt
	return m
}
Exemple #3
0
func Render(temp string, r Request) {
	dir, _ := os.Getwd()
	f := strings.Join([]string{dir, "settings.json"}, "/")
	config := config.Load_config(f)
	f = strings.Join([]string{config.Home, config.Apps[0], config.Templates[0], temp}, "/")
	t := TemplateConfig{config, r}
	text, err := ioutil.ReadFile(f)
	t.Load(string(text))
	check(err)
}
Exemple #4
0
func new_project(name string) {
	base := filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "r0fls", "reinhardt")
	os.MkdirAll(filepath.Join(name, "app", "models"), 0700)
	text, err := ioutil.ReadFile(filepath.Join(base, "src", "app_files", "models.go"))
	check(err)
	err = ioutil.WriteFile(filepath.Join(name, "app", "models", "models.go"), text, 0644)
	check(err)

	os.Mkdir(filepath.Join(name, "app", "views"), 0700)

	text, err = ioutil.ReadFile(filepath.Join(base, "src", "app_files", "views.go"))
	check(err)
	err = ioutil.WriteFile(filepath.Join(name, "app", "views", "views.go"), text, 0644)
	check(err)

	os.Mkdir(filepath.Join(name, "app", "temps"), 0700)

	text, err = ioutil.ReadFile(filepath.Join(base, "src", "app_files", "home.html"))
	check(err)
	err = ioutil.WriteFile(filepath.Join(name, "app", "temps", "home.html"), text, 0644)
	check(err)

	text, err = ioutil.ReadFile(filepath.Join(base, "src", "app_files", "settings.json"))
	check(err)
	dir, _ := os.Getwd()
	gopath := os.Getenv("GOPATH")
	local, _ := filepath.Rel(gopath, dir)
	local, _ = filepath.Rel("src", local)
	if string([]rune(local)[0]) == "/" || string([]rune(local)[0]) == "\\" {
		local = local[1:]
	}
	local = filepath.Join(local, name)
	err = ioutil.WriteFile(filepath.Join(name, "settings.json"), []byte(fmt.Sprintf(string(text), dir, name, gopath, local)), 0644)
	check(err)

	c := config.Load_config(filepath.Join(name, "settings.json"))
	text, err = ioutil.ReadFile(filepath.Join(base, "src", "app_files", "manager.go"))
	check(err)
	tmpl, _ := template.New("manager").Parse(string(text))
	f, err := os.Create(filepath.Join(name, "manager.go"))
	check(err)
	err = tmpl.Execute(f, c)
	check(err)

	text, err = ioutil.ReadFile(filepath.Join(base, "src", "app_files", "urls.go"))
	check(err)
	tmpl, _ = template.New("urls").Parse(string(text))
	f, err = os.Create(filepath.Join(name, "app", "urls.go"))
	check(err)
	err = tmpl.Execute(f, c)
	check(err)
}
Exemple #5
0
func run_server(location string) {
	config := config.Load_config(location)
	// should loop through all apps
	Urls := app.Urls()
	http.Handle("/", http.HandlerFunc(Urls.Routes))
	if config.StaticDir != "" {
		fs := http.FileServer(http.Dir(config.StaticDir))
		static := fmt.Sprintf("/%s/", config.Static)
		http.Handle(static, http.StripPrefix(static, fs))
	}
	ap := []string{config.Address, config.Port}
	fmt.Printf("Serving on %s:%s\n", config.Address, config.Port)
	log.Fatal(http.ListenAndServe(strings.Join(ap, ":"), nil))
}