Exemplo n.º 1
0
// Forces the session to be saved to disk. Note that the sessions are saved to disk on each change currently, since there are very few changes.
func (s *Session) Save() (err os.Error) {
	filename := "data/shared/sessions/" + strconv.Itoa64(s.ID)
	fmt.Println(filename)
	err = ini.Save(filename, s.settings)
	if err != nil {
		dlog.Println("Warning: Error loading session data:", err)
		return err
	}
	return
}
Exemplo n.º 2
0
// Convieniance function to get the session object for a request based on the
// value of the sessionid cookie. Creates a new session if none is found.
func Get(c http.ResponseWriter, r *http.Request) (s *Session) {
	s, e := GetExisting(r)
	if e == nil {
		return
	}
	s = New()
	s.AttachTo(c)
	dlog.Println("New session created:", s)
	return
}
Exemplo n.º 3
0
// Forces the session to be reloaded from disk.
func (s *Session) Load() (err os.Error) {
	filename := "data/shared/sessions/" + strconv.Itoa64(s.ID)
	fmt.Println(filename)
	s.settings, err = ini.Load(filename)
	if err != nil {
		dlog.Println("Warning: Error saving session data:", err)
		return err
	}
	return nil
}
Exemplo n.º 4
0
// Save a map of settings to filename in name=value format. Returns nil on success, error otherwise.
func Save(filename string, settings map[string]string) (e os.Error) {
	dirname, _ := path.Split(filename)
	err := os.MkdirAll(dirname, 0755)
	if err != nil {
		dlog.Println("Error creating directory to save ini file", filename, ":", err)
		return err
	}

	file, e := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
	if e != nil {
		dlog.Printf("Failed to open %s, %s.\n", filename, e)
		return
	}
	for key, value := range settings {
		fmt.Fprintf(file, "%s=%s\n", key, value)
	}
	return
}