Documentation ¶
Overview ¶
Example ¶
package main import ( "fmt" "log" "github.com/unqnown/iof" ) type Data struct { V interface{} } func main() { if err := iof.JSON.Write("test.json", Data{V: "ʕ•ᴥ•ʔ"}); err != nil { log.Fatal(err) } var read Data if err := iof.JSON.Read("test.json", &read); err != nil { log.Fatal(err) } fmt.Printf("%v", read.V) }
Output: ʕ•ᴥ•ʔ
Index ¶
- Constants
- Variables
- func Insert(name string, v interface{}) error
- func Read(name string, v interface{}) error
- func RegisterEncoding(ext string, enc Encoding)
- func Update(name string, v interface{}) error
- func Upsert(name string, v interface{}) error
- func Write(name string, v interface{}) error
- type Encoding
- type ReadWriter
- type Reader
- type Writer
Examples ¶
Constants ¶
View Source
const CSV csv = ".csv"
CSV is Encoding implementation for "csv" data format.
View Source
const GOB gob = ".gob"
GOB is Encoding implementation for "gob" data format.
View Source
const JSON json = ".json"
JSON is Encoding implementation for "json" data format.
View Source
const XML xml = ".xml"
XML is Encoding implementation for "xml" data format.
View Source
const YAML yaml = ".yaml"
YAML is Encoding implementation for "yaml" data format.
Variables ¶
View Source
var ( // ErrAlreadyExists means that that resource of given name already exists. ErrAlreadyExists = errors.New("iof: already exists") // ErrNotExists means that that resource of given name not exists. ErrNotExists = errors.New("iof: not exists") // ErrNotFile means that resource of given name is not a file. ErrNotFile = errors.New("iof: not file") )
Functions ¶
func Read ¶
Read decodes content of a file to the given value via Encoding resolved from file's extension.
func RegisterEncoding ¶
RegisterEncoding makes new Encoding available for resolving by file extension.
func Update ¶
Update encodes given value to the existing file via Encoding resolved from file's extension.
Types ¶
type Encoding ¶
type Encoding interface { fmt.Stringer Reader Writer // Insert creates a new file with the content of encoded value. // If file already exists returns ErrAlreadyExists. Insert(name string, v interface{}) error // Update updates existing file with content of encoded value. // If file not exists returns ErrNotExists. Update(name string, v interface{}) error // Upsert is an alias for Write method. Upsert(name string, v interface{}) error }
Encoding represents interface for file i/o workflow.
type ReadWriter ¶
Click to show internal directories.
Click to hide internal directories.