mirror of
https://github.com/Luzifer/mondash.git
synced 2024-11-14 02:12:42 +00:00
Knut Ahlers
f3c31476b4
* Update dependencies * Improve code quality * Apply linter advices * Add gzip compression to all requests * Rework frontend * Apply bootswatch theme * Hide historic details when not requested * Remove debugging header * Apply auto-migration of meta fields * Fix broken "last update" time * Pre-sort metrics for frontend / API * Add tooltip with absolute time * Some design fixes * Add tooltip with absolute date to last ok * Implement filters * Apply eslint --fix * Remove unused var * Remove remains of old template engine * Update baked in assets * Update Dockerfile for new version Signed-off-by: Knut Ahlers <knut@ahlers.me>
51 lines
996 B
Go
51 lines
996 B
Go
package ini
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
|
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
|
)
|
|
|
|
// OpenFile takes a path to a given file, and will open and parse
|
|
// that file.
|
|
func OpenFile(path string) (Sections, error) {
|
|
f, err := os.Open(path)
|
|
if err != nil {
|
|
return Sections{}, awserr.New(ErrCodeUnableToReadFile, "unable to open file", err)
|
|
}
|
|
defer f.Close()
|
|
|
|
return Parse(f)
|
|
}
|
|
|
|
// Parse will parse the given file using the shared config
|
|
// visitor.
|
|
func Parse(f io.Reader) (Sections, error) {
|
|
tree, err := ParseAST(f)
|
|
if err != nil {
|
|
return Sections{}, err
|
|
}
|
|
|
|
v := NewDefaultVisitor()
|
|
if err = Walk(tree, v); err != nil {
|
|
return Sections{}, err
|
|
}
|
|
|
|
return v.Sections, nil
|
|
}
|
|
|
|
// ParseBytes will parse the given bytes and return the parsed sections.
|
|
func ParseBytes(b []byte) (Sections, error) {
|
|
tree, err := ParseASTBytes(b)
|
|
if err != nil {
|
|
return Sections{}, err
|
|
}
|
|
|
|
v := NewDefaultVisitor()
|
|
if err = Walk(tree, v); err != nil {
|
|
return Sections{}, err
|
|
}
|
|
|
|
return v.Sections, nil
|
|
}
|