I can reproduce your problem by inserting the BOM in front of the file. printf '\xEF\xBB\xBF;blah\nff=ff' > test.ini
A quick and dirty fix might look like this, it wraps the read operation with a bomskipreader, which jobs is to detect and get ride of the bom if detected, thus its like it was never there was when the vendor read lines at https://github.com/vaughan0/go-ini/blob/master/ini.go#L76 package main import ( "fmt" "io" "os" ini "github.com/vaughan0/go-ini" ) func main() { file, err := os.Open("test.ini") if err != nil { panic(err) } ini, err := ini.Load(&bomSkipReader{R: file}) if err != nil { panic(err) } fmt.Println(ini) } // the quick and dirty way. type bomSkipReader struct { R io.Reader sent bool } func (l bomSkipReader) Read(p []byte) (int, error) { n, err := l.R.Read(p) if l.sent == false { if len(p) > 3 { if p[0] == 0xef && p[1] == 0xbb && p[2] == 0xbf { p = append(p[:0], p[3:]...) n -= 3 } l.sent = true } } fmt.Printf("%#v\n", p[:5]) return n, err } PS: something is flaky with the editor of this NG :x On Saturday, January 14, 2017 at 5:46:47 PM UTC+1, [email protected] wrote: > > Rankest beginner here. Trying to learn Go by converting an old Visual > Basic application to Go (yeah, right) on Windows 10 (got all the database > stuff working with both postgre and sqlite!) The application needs to read > an .ini file to get path/filename. It bombs on the first line. > > This is from my testing platform. I like doing things in baby steps, > please. > > package main > > import ( > "fmt" > > ini "github.com/vaughan0/go-ini" > ) > > func main() { > pathfilename := readINIfile() > fmt.Println(pathfilename) > } > > func readINIfile() string { > _, err := ini.LoadFile("C:\\temp\\testfile.ini") > if err != nil { > fmt.Println(err) > } > return "" > } > > I can't get beyond the first err test. The error returned is: "invalid > INI syntax on line 1: ;blah". It is choking on the ';blah'. Also chokes > on a blank line and on simply the ';' character. The author's > documentation says: > > INI files are parsed by go-ini line-by-line. Each line may be one of the > following: > > - A section definition: [section-name] > - A property: key = value > - A comment: #blahblah *or* ;blahblah > - Blank. The line will be ignored. > > I've stared at this for hours. Any idea what I'm missing? > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
