func log(user string, amount string, comment string) error { if onlyAdmin { if err := sec.AdminOn(); err != nil { return err } } tstamp := time.Now().Format(time.RFC1123) f, err := os.OpenFile(buxLog(user), os.O_RDWR|os.O_APPEND, 0666) if err != nil { return err } fmt.Fprintf(f, "%s %s %s %s\n", tstamp, user, amount, comment) defer f.Close() if onlyAdmin { if err := sec.AdminOff(); err != nil { return err } } return nil }
// Add or remove bux for the given user with required comment. func Adjust(amount interface{}, user string, comment string) error { if onlyAdmin { if err := sec.AdminOn(); err != nil { return err } } switch v := amount.(type) { case int: amount = strconv.Itoa(v) } if err := c.AddInt(buxFile(user), amount.(string)); err != nil { return err } if err := log(user, amount.(string), comment); err != nil { return err } if onlyAdmin { if err := sec.AdminOff(); err != nil { return err } } return nil }