How to use SaveFile method of config Package

Best Syzkaller code snippet using config.SaveFile

io.go

Source:io.go Github

copy

Full Screen

...63 return err64 }65 return nil66}67func (g *game) RemoveSaveFile() error {68 return g.RemoveDataFile("save")69}70func (g *game) Load() (bool, error) {71 dataDir, err := g.DataDir()72 if err != nil {73 return false, err74 }75 saveFile := filepath.Join(dataDir, "save")76 _, err = os.Stat(saveFile)77 if err != nil {78 // no save file, new game79 return false, err80 }81 data, err := ioutil.ReadFile(saveFile)...

Full Screen

Full Screen

instance_state.go

Source:instance_state.go Github

copy

Full Screen

...32 saveFile: saveFile,33 format: format,34 }35}36func (is *InstanceState) checkSaveFile() bool {37 return is.saveFile != nil38}39func (is *InstanceState) getSaveFileContents() []byte {40 if !is.checkSaveFile() {41 return nil42 }43 finfo, err := is.saveFile.Stat()44 if err != nil {45 panic(err)46 }47 size := finfo.Size()48 if size > 0xffffffff {49 panic("savePath too large")50 }51 intSize := int(size)52 buf := cachepool.RawMallocByteSlice(intSize)53 n, _ := is.saveFile.ReadAt(buf, 0)54 return buf[:n]55}56//Get 获取断点续传信息57func (is *InstanceState) Get() (eii *transfer.DownloadInstanceInfo) {58 if !is.checkSaveFile() {59 return nil60 }61 is.mu.Lock()62 defer is.mu.Unlock()63 contents := is.getSaveFileContents()64 if len(contents) <= 0 {65 return66 }67 is.ii = &transfer.DownloadInstanceInfoExport{}68 var err error69 switch is.format {70 case InstanceStateStorageFormatProto3:71 err = proto.Unmarshal(contents, is.ii.(*transfer.DownloadInstanceInfoExport))72 default:73 err = jsoniter.Unmarshal(contents, is.ii)74 }75 if err != nil {76 pcsverbose.Verbosef("DEBUG: InstanceInfo unmarshal error: %s\n", err)77 return78 }79 eii = is.ii.GetInstanceInfo()80 return81}82//Put 提交断点续传信息83func (is *InstanceState) Put(eii *transfer.DownloadInstanceInfo) {84 if !is.checkSaveFile() {85 return86 }87 is.mu.Lock()88 defer is.mu.Unlock()89 if is.ii == nil {90 is.ii = &transfer.DownloadInstanceInfoExport{}91 }92 is.ii.SetInstanceInfo(eii)93 var (94 data []byte95 err error96 )97 switch is.format {98 case InstanceStateStorageFormatProto3:99 data, err = proto.Marshal(is.ii.(*transfer.DownloadInstanceInfoExport))100 default:101 data, err = jsoniter.Marshal(is.ii)102 }103 if err != nil {104 panic(err)105 }106 err = is.saveFile.Truncate(int64(len(data)))107 if err != nil {108 pcsverbose.Verbosef("DEBUG: truncate file error: %s\n", err)109 }110 _, err = is.saveFile.WriteAt(data, 0)111 if err != nil {112 pcsverbose.Verbosef("DEBUG: write instance state error: %s\n", err)113 }114}115//Close 关闭116func (is *InstanceState) Close() error {117 if !is.checkSaveFile() {118 return nil119 }120 return is.saveFile.Close()121}122func (der *Downloader) initInstanceState(format InstanceStateStorageFormat) (err error) {123 if der.instanceState != nil {124 return errors.New("already initInstanceState")125 }126 var saveFile *os.File127 if !der.config.IsTest && der.config.InstanceStatePath != "" {128 saveFile, err = os.OpenFile(der.config.InstanceStatePath, os.O_RDWR|os.O_CREATE, 0777)129 if err != nil {130 return err131 }...

Full Screen

Full Screen

app.go

Source:app.go Github

copy

Full Screen

1package cache2/**3 * This file is part of Gourd.4 *5 * @link http://gourd.kyour.cn6 * @document http://gourd.kyour.cn/doc7 * @contact kyour@vip.qq.com8 * @license https://https://github.com/kyour-cn/gourd/blob/master/LICENSE9 */10import (11 "github.com/kyour-cn/gourd/common"12 "github.com/kyour-cn/gourd/utils/gut"13 "log"14 "time"15)16var Obj Cache17var isInit bool18type Config struct {19 //是否启用20 Enable bool `toml:"enable"`21 //缓存默认过期时间(秒) ,传递-1时取此值22 Expiration int32 `toml:"expiration"`23 //是否实时输出到缓存文件24 RealtimeSave bool `toml:"realtime_save"`25 //缓存文件保存周期(秒),realtime_save=false 才会生效26 SavefileCycle int32 `toml:"savefile_cycle"`27 //缓存文件保存路径28 SavefilePath string `toml:"savefile_path"`29}30var config Config31//初始化缓存32func Init() {33 //判断是否未初始化34 if !isInit {35 err := common.ReadConfig("cache", &config)36 if err != nil {37 log.Printf("Cache 配置错误:%v\n", err)38 }39 if !config.Enable {40 //不启用缓存41 return42 }43 //创建缓存对象44 Obj = *NewCache(time.Duration(config.Expiration)*time.Second, time.Duration(config.SavefileCycle)*time.Second, config.SavefilePath)45 if config.SavefilePath != "" {46 exist, err := gut.PathExists(config.SavefilePath)47 if err != nil {48 log.Printf("Cache PathExists Error:%v\n", err)49 }50 if exist {51 //读取文件52 err = Obj.LoadFile(config.SavefilePath)53 if err != nil {54 log.Printf("Cache Error:%v\n", err)55 }56 }57 }58 //已初始化59 isInit = true60 //实时保存关闭-定时保存61 //if !config.RealtimeSave {62 //log.Printf("Cache.Init \n", Obj.Items)63 //time.AfterFunc(5*time.Minute, func() {64 //65 // log.Printf("expired")66 //67 //})68 //time.Duration(config.SavefileCycle)*time.Second69 /*70 go func() {71 tick := time.NewTicker(time.Duration(config.SavefileCycle) * time.Second)72 for {73 select {74 case <-tick.C:75 //log.Printf("Cache.Item:%v\n", Obj.Count())76 //定时执行保存数据77 _ = Obj.SaveToFile(config.SavefilePath)78 Obj.DeleteExpired()79 }80 }81 }()82 */83 /*84 time.AfterFunc(time.Minute, func() {85 for {86 //time.Sleep(time.Duration(config.SavefileCycle) * time.Second)87 log.Printf("Cache.Item:%v\n", len(Obj.Items))88 //定时执行保存数据89 _ = Obj.SaveToFile(config.SavefilePath)90 }91 })92 */93 //}94 }95}96//设置数据97func Set(k string, v interface{}, second int) {98 Init()99 Obj.Set(k, v, time.Duration(second)*time.Second)100 //如果实时保存101 if config.RealtimeSave {102 err := Obj.SaveToFile(config.SavefilePath)103 if err != nil {104 log.Fatalf("Cache SaveToFile Error:%v", err)105 }106 }107}108//获取缓存数据109func Get(key string) (interface{}, bool) {110 Init()111 return Obj.Get(key)112}113func Add(k string, v interface{}, second int) (err error) {114 Init()115 err = Obj.Add(k, v, time.Duration(second)*time.Second)116 //如果实时保存117 if config.RealtimeSave {118 err = Obj.SaveToFile(config.SavefilePath)119 if err != nil {120 log.Printf("Cache Add Error:%v", err)121 }122 }123 return124}...

Full Screen

Full Screen

SaveFile

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 api := rest.NewApi()4 api.Use(rest.DefaultDevStack...)5 router, err := rest.MakeRouter(6 rest.Post("/save", SaveFile),7 if err != nil {8 log.Fatal(err)9 }10 api.SetApp(router)11 log.Fatal(http.ListenAndServe(":8080", api.MakeHandler()))12}13func SaveFile(w rest.ResponseWriter, r *rest.Request) {14 fmt.Println("SaveFile method called")15 w.WriteJson(map[string]string{"Body": "SaveFile method called"})16}17import (18func main() {19 api := rest.NewApi()20 api.Use(rest.DefaultDevStack...)21 router, err := rest.MakeRouter(22 rest.Post("/load", LoadFile),23 if err != nil {24 log.Fatal(err)25 }26 api.SetApp(router)27 log.Fatal(http.ListenAndServe(":8080", api.MakeHandler()))28}29func LoadFile(w rest.ResponseWriter, r *rest.Request) {30 fmt.Println("LoadFile method called")31 w.WriteJson(map[string]string{"Body": "LoadFile method called"})32}33import (34func main() {35 api := rest.NewApi()36 api.Use(rest.DefaultDevStack...)37 router, err := rest.MakeRouter(38 rest.Post("/delete", DeleteFile),39 if err != nil {40 log.Fatal(err)41 }42 api.SetApp(router)43 log.Fatal(http.ListenAndServe(":8080", api.MakeHandler()))44}45func DeleteFile(w rest.ResponseWriter, r *rest.Request) {46 fmt.Println("DeleteFile method called")47 w.WriteJson(map[string]string{"Body": "DeleteFile method called"})48}49import (50func main() {51 api := rest.NewApi()52 api.Use(rest.DefaultDevStack

Full Screen

Full Screen

SaveFile

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 cfg, err := config.NewConfig("ini", "conf/app.conf")4 if err != nil {5 fmt.Println("new config failed, err:", err)6 }7 err = cfg.SaveConfigFile("my.ini")8 if err != nil {9 fmt.Println("save config file failed, err:", err)10 }11 os.Exit(0)12}13import (14func main() {15 cfg, err := config.NewConfig("ini", "conf/app.conf")16 if err != nil {17 fmt.Println("new config failed, err:", err)18 }19 cfg.Set("astaxie", "beego")20 cfg.Set("beego", "astaxie")21 fmt.Println(cfg.String("astaxie"))22 fmt.Println(cfg.String("beego"))23}24import (25func main() {26 cfg, err := config.NewConfig("ini", "conf/app.conf")27 if err != nil {28 fmt.Println("new config failed, err:", err)29 }30 cfg.Del("astaxie")31 fmt.Println(cfg.String("astaxie"))32}33import (34func main() {35 cfg, err := config.NewConfig("ini", "conf/app.conf")36 if err != nil {37 fmt.Println("new config failed, err:", err)38 }

Full Screen

Full Screen

SaveFile

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 golconfig.SaveFile("2.go", "2.go")4}5import (6func main() {7 fmt.Println(golconfig.Get("3.go", "3.go"))8}9import (10func main() {11 golconfig.Set("4.go", "4.go", "4.go")12 fmt.Println(golconfig.Get("4.go", "4.go"))13}14import (15func main() {16 fmt.Println(golconfig.GetKeys("5.go"))17}18import (19func main() {20 fmt.Println(golconfig.GetKeys("6.go"))21}22import (23func main() {24 fmt.Println(golconfig.GetKeys("7.go"))25}26import (27func main() {28 fmt.Println(golconfig.GetKeys("8.go"))29}30import (31func main() {32 fmt.Println(golconfig.GetKeys("9.go"))33}

Full Screen

Full Screen

SaveFile

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 c := config.NewConfig()4 c.Set("name", "John")5 c.Set("age", 25)6 c.Set("married", false)7 c.Set("hobbies", []string{"music", "skiing", "reading"})8 c.SaveFile("config.json")9 fmt.Println("Config saved to file")10}

Full Screen

Full Screen

SaveFile

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 conf := config.NewConfig()4 err := conf.SaveFile("config.json")5 if err != nil {6 fmt.Println(err)7 }8}9{10}11import (12func main() {13 conf := config.NewConfig()14 err := conf.SaveFileIndent("config.json", "", " ")15 if err != nil {16 fmt.Println(err)17 }18}19{20}21import (22func main() {23 conf := config.NewConfig()24 err := conf.SaveFilePretty("config.json", "", " ")25 if err != nil {26 fmt.Println(err)27 }28}29{30}31import (32func main() {33 conf := config.NewConfig()

Full Screen

Full Screen

SaveFile

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 c := config.NewConfig("config.json")4 c.SaveFile("config.json")5 fmt.Println("Config file saved")6}7import (8func main() {9 c := config.NewConfig("config.json")10 fmt.Println(c.Get("key1"))11}12import (13func main() {14 c := config.NewConfig("config.json")15 c.Set("key1", "value1")16 fmt.Println(c.Get("key1"))17}18import (19func main() {20 c := config.NewConfig("config.json")21 if c.Has("key1") {22 fmt.Println("Key exists")23 } else {24 fmt.Println("Key does not exist")25 }26}27import (28func main() {29 c := config.NewConfig("config.json")30 c.Delete("key1")31 fmt.Println(c.Get("key1"))32}33import (34func main() {35 c := config.NewConfig("config.json")36 c.Set("key1", "value1")37 c.Save()38 fmt.Println(c.Get("key1"))39}40import (41func main() {42 c := config.NewConfig("config.json")43 c.Set("key1", "value1")44 c.Save()45 fmt.Println(c.Get("key1"))46 c.Load()47 fmt.Println(c.Get("key1"))48}

Full Screen

Full Screen

SaveFile

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 c := config.NewConfig("config.json")4 c.SaveFile("config_new.json")5 fmt.Println("File saved")6}7import (8func main() {9 c := config.NewConfig("config.json")10 c.LoadFile("config_new.json")11 fmt.Println("File loaded")12}13import (14func main() {15 c := config.NewConfig("config.json")16 c.Set("name", "Ashish")17 fmt.Println(c.Get("name"))18}19import (20func main() {21 c := config.NewConfig("config.json")22 fmt.Println(c.Get("name"))23}24import (25func main() {26 c := config.NewConfig("config.json")27 fmt.Println(c.GetBool("is_active"))28}29import (30func main() {31 c := config.NewConfig("config.json")32 fmt.Println(c.GetFloat64("amount"))33}34import (35func main() {36 c := config.NewConfig("config.json")37 fmt.Println(c.GetInt64("age"))38}39import (40func main() {41 c := config.NewConfig("config.json")42 fmt.Println(c.GetString("name"))43}44import (45func main() {46 c := config.NewConfig("config.json")47 fmt.Println(c.GetStringSlice("names"))48}

Full Screen

Full Screen

SaveFile

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 c := config.Config{}4 m := make(map[string]string)5 err := c.SaveFile(m, "config.txt")6 if err != nil {7 fmt.Println(err)8 }9}10import (11func main() {12 c := config.Config{}13 m, err := c.LoadFile("config.txt")14 if err != nil {15 fmt.Println(err)16 }17 fmt.Println(m)18}19import (20func main() {21 c := config.Config{}22 m := make(map[string]string)23 err := c.SaveFile(m, "config.txt")24 if err != nil {25 fmt.Println(err)26 }27 m, err = c.LoadFile("config.txt")28 if err != nil {29 fmt.Println(err)30 }31 fmt.Println(m)32}33import (34func main() {35 c := config.Config{}36 m := make(map[string]string)

Full Screen

Full Screen

SaveFile

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 c := config.New()4 c.Set("name", "krishna")5 err := c.SaveFile("config.json")6 if err != nil {7 fmt.Println(err.Error())8 os.Exit(1)9 }10}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful