You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
fabric/db/contexts.go

36 lines
574 B
Go

package db
import (
"os"
)
type Contexts struct {
*Storage
}
// LoadContext Load a context from file
func (o *Contexts) LoadContext(name string) (ret *Context, err error) {
path := o.BuildFilePathByName(name)
var content []byte
if content, err = os.ReadFile(path); err != nil {
return
}
ret = &Context{Name: name, Content: string(content)}
return
}
type Context struct {
Name string
Content string
contexts *Contexts
}
// Save the session on disk
func (o *Context) Save() (err error) {
err = o.contexts.Save(o.Name, []byte(o.Content))
return err
}