github.com/marinho/drone@v0.2.1-0.20140504195434-d3ba962e89a7/pkg/database/settings.go (about) 1 package database 2 3 import ( 4 . "github.com/drone/drone/pkg/model" 5 "github.com/russross/meddler" 6 ) 7 8 // Name of the Settings table in the database 9 const settingsTable = "settings" 10 11 // SQL Queries to retrieve the system settings 12 const settingsStmt = ` 13 SELECT id, github_key, github_secret, github_domain, github_apiurl, bitbucket_key, bitbucket_secret, 14 gitlab_domain, gitlab_apiurl, smtp_server, smtp_port, smtp_address, smtp_username, smtp_password, 15 hostname, scheme, open_invitations FROM settings WHERE id = 1 16 ` 17 18 //var ( 19 // // mutex for locking the local settings cache 20 // settingsLock sync.Mutex 21 // 22 // // cached settings 23 // settingsCache = &Settings{} 24 //) 25 26 // Returns the system Settings. 27 func GetSettings() (*Settings, error) { 28 //settingsLock.Lock() 29 //defer settingsLock.Unlock() 30 31 // return a copy of the settings 32 //if settingsCache.ID == 0 { 33 /// settingsCopy := &Settings{} 34 // *settingsCopy = *settingsCache 35 // return settingsCopy, nil 36 //} 37 38 settings := Settings{} 39 err := meddler.QueryRow(db, &settings, settingsStmt) 40 //if err == sql.ErrNoRows { 41 // // we ignore the NoRows error in case this 42 // // is the first time the system is being used 43 // err = nil 44 //} 45 return &settings, err 46 } 47 48 // Returns the system Settings. This is expected 49 // always pass, and will panic on failure. 50 func SettingsMust() *Settings { 51 settings, err := GetSettings() 52 if err != nil { 53 panic(err) 54 } 55 return settings 56 } 57 58 // Saves the system Settings. 59 func SaveSettings(settings *Settings) error { 60 //settingsLock.Lock() 61 //defer settingsLock.Unlock() 62 63 // persist changes to settings 64 err := meddler.Save(db, settingsTable, settings) 65 if err != nil { 66 return err 67 } 68 69 // store updated settings in cache 70 //*settingsCache = *settings 71 return nil 72 }