예제 #1
0
func (c *Config) readDir(configDir string) []byte {
	fis, err := ioutil.ReadDir(configDir)
	if err != nil {
		log.Fatal("<Config.readDir> error: ", err)
	}

	lfis := len(fis)
	chContent := make(chan []byte, lfis)

	for _, fi := range fis {
		go func(chContent chan []byte, configPath string) {
			chContent <- c.format(configPath)
		}(chContent, configDir+"/"+fi.Name())
	}

	contentBuf := bytes.NewBufferString(`{`)
	for i := 1; i <= lfis; i++ {
		content := <-chContent
		if len(content) == 0 {
			continue
		}

		contentBuf.Write(content)
		if i < lfis {
			contentBuf.WriteString(",")
		}
	}

	contentBuf.WriteString(`}`)

	return contentBuf.Bytes()
}
예제 #2
0
func (c *Config) format(configPath string) []byte {
	data, err := ioutil.ReadFile(configPath)
	if err != nil {
		log.Fatal("<Config.format> error: ", err)
	}

	return bytes.TrimSpace(regexpSpace.ReplaceAll(regexpNote.ReplaceAll(data, []byte(``)), []byte(``)))
}
예제 #3
0
func (c *Config) format(configPath string) []byte {
	data, err := ioutil.ReadFile(configPath)
	if err != nil {
		log.Fatal("<Config.format> ", err)
	}

	return regexp.MustCompile(`#.*\n`).ReplaceAll(data, []byte("\n"))
}
예제 #4
0
파일: page.go 프로젝트: gaiyongbo/framework
func (p *Page) ListenAndServe(addr string, i interface{}) {
	if p.Config.SupportStatic {
		p.handleRootStatic(p.Config.RootStaticFiles)
		p.handleStatic()
	}

	p.handleRoute(i)

	err := http.ListenAndServe(addr, nil)
	if err != nil {
		log.Fatal("<Page.ListenAndServe> ", err)
	}
}
예제 #5
0
func (c *Config) load(data []byte) {
	err := json.Unmarshal(data, c)
	if err != nil {
		log.Debug("<Config.Load> jsonData: ", string(data))
		log.Fatal("<Config.Load> error: ", err)
	}

	c.UploadDirectory = c.AssetsDirectory + c.StaticDirectory + c.UploadDirectory
	c.ThemeDirectory = c.ThemeDirectory + c.Theme + "/"
	c.StaticCssDirectory = c.AssetsDirectory + c.StaticDirectory + c.ThemeDirectory + c.StaticCssDirectory
	c.StaticJsDirectory = c.AssetsDirectory + c.StaticDirectory + c.ThemeDirectory + c.StaticJsDirectory
	c.StaticImgDirectory = c.AssetsDirectory + c.StaticDirectory + c.ThemeDirectory + c.StaticImgDirectory
}
예제 #6
0
func (c *Config) Load(configDir string) {
	data := c.readDir(configDir)
	err := json.Unmarshal(data, c)
	if err != nil {
		log.Debug("<Config.Load> jsonData: ", string(data))
		log.Fatal("<Config.Load> error: ", err)
	}

	c.UploadDirectory = c.AssetsDirectory + c.StaticDirectory + c.UploadDirectory
	c.ThemeDirectory = c.ThemeDirectory + c.Theme + "/"
	c.StaticCssDirectory = c.AssetsDirectory + c.StaticDirectory + c.ThemeDirectory + c.StaticCssDirectory
	c.StaticJsDirectory = c.AssetsDirectory + c.StaticDirectory + c.ThemeDirectory + c.StaticJsDirectory
	c.StaticImgDirectory = c.AssetsDirectory + c.StaticDirectory + c.ThemeDirectory + c.StaticImgDirectory

	c.configDir = configDir
	dataFi, _ := os.Stat(configDir)
	c.configLastModTime = dataFi.ModTime().Unix()
}