diff options
| -rw-r--r-- | jobedit.go | 28 | ||||
| -rw-r--r-- | mailremind.ini | 8 | ||||
| -rw-r--r-- | main.go | 1 | 
3 files changed, 28 insertions, 9 deletions
| @@ -53,11 +53,22 @@ func chronToSchedTL(chron chronos.Chronos, u model.User) scheduleTpldata {  	return schedule  } -// TODO: Make these constants variable (config file or something...) -const ( -	maxSchedules = 10 -	jobsLimit    = 100 -) +var maxSchedules, jobsLimit int + +func initLimits() { +	schedules, err := conf.GetInt("limits", "schedules") +	if err != nil { +		log.Fatalf("Could not read config limits.schedules: %s", err) +	} + +	jobs, err := conf.GetInt("limits", "jobs") +	if err != nil { +		log.Fatalf("Could not read config limits.jobs: %s", err) +	} + +	maxSchedules = int(schedules) +	jobsLimit = int(jobs) +}  const bestTimeFmtEver = "2006-01-02 15:04:05" @@ -65,16 +76,17 @@ type jobeditTpldata struct {  	Error, Success          string  	Fatal                   bool  	JobID, Subject, Content string -	Schedules               [maxSchedules]scheduleTpldata +	Schedules               []scheduleTpldata  }  func (jt *jobeditTpldata) fillFromJob(job model.Job, u model.User) {  	jt.JobID = job.ID().String()  	jt.Subject = job.Subject()  	jt.Content = string(job.Content()) +	jt.Schedules = make([]scheduleTpldata, maxSchedules)  	for i, chron := range job.Chronos() { -		if i == 10 { +		if i == maxSchedules {  			log.Printf("Job %s has more than %d Chronos entries!", job.ID(), maxSchedules)  			break  		} @@ -193,7 +205,7 @@ func jobedit(user model.User, sess *sessions.Session, req *http.Request) (interf  		return &jobeditTpldata{Error: "You need to be logged in to do that.", Fatal: true}, user  	} -	outdata := new(jobeditTpldata) +	outdata := &jobeditTpldata{Schedules: make([]scheduleTpldata, maxSchedules)}  	// Try to load job, if given  	_id := mux.Vars(req)["ID"] diff --git a/mailremind.ini b/mailremind.ini index eb498d7..a4be249 100644 --- a/mailremind.ini +++ b/mailremind.ini @@ -28,4 +28,10 @@ arg2=kch42  [schedules]  # How often should the schedules be checked? Unit is seconds. -checkInterval=30
\ No newline at end of file +checkInterval=30 + +[limits] +# How many schedules? MUST be > 0 +schedules=10 +# How many jobs per user? If < 0, unlimited. +jobs=100
\ No newline at end of file @@ -66,6 +66,7 @@ func main() {  	initMailing()  	initMails()  	initDB() +	initLimits()  	defer dbcon.Close()  	staticpath, err := conf.GetString("paths", "static") | 
