I'm writing a golang web application. The web application accesses the file system (reading and writing) and an sqlite3 database file.
Question 1: How can I synchronize file system access in Go?
type DataObject struct {
data []byte
}
func (*d DataObject) Write() {
//
// Synchronization ?
//
ioutil.WriteFile("file.name", d.data, 0644)
//
// Stop synchronization ?
//
}
Question 2: Do I need to synchronize sqlite3 database file access?
type SqlObject struct {
sqldata string
}
func (*s SqlObject) Store() error {
//
// Open the file, do I need some sort of synchronization?
//
con, err := sqlite.Open("database/datafile.db")
if err != nil {
return err
}
defer con.Close()
err = con.Exec("INSERT INTO data(sqldata) values(?)", s.sqldata)
if err != nil {
return err
}
return nil
}
I'm using the gosqlite3 driver (http://code.google.com/p/gosqlite/).