mirror of
https://github.com/danielmiessler/fabric
synced 2024-11-10 07:10:31 +00:00
36 lines
574 B
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
|
||
|
}
|