func (p *Post) Delete(name string) (err error) { if !CedUtils.Exist("public") { os.Mkdir("public", 0755) } if CedUtils.Exist(filepath.Join("public", name)) { err := os.Remove(filepath.Join("public", name)) if err != nil { return err } } return nil }
func (p *Post) New(name string) (err error) { if !CedUtils.Exist("public") { os.Mkdir("public", 0755) } if CedUtils.Exist(filepath.Join("public", name)) { fmt.Println("File is Exist") return } // 创建文件失败error file, err := os.OpenFile(filepath.Join("public", name), os.O_WRONLY|os.O_CREATE, 0644) defer file.Close() if err != nil { return err } p.path = name p.fileName = name _, err = file.Write([]byte(p.fileName)) return nil }
func (c *Config) Read() *Config { if CedUtils.Exist(ConfigPath) { file, err := os.Open(ConfigPath) if err != nil { return nil } defer file.Close() data, err := ioutil.ReadAll(file) if err != nil { return nil } err = json.Unmarshal(data, c) if err != nil { return nil } return c } else { c.New() c.Read() } return c }