From 0ef8fcb03fc4f51b8bc6b1a24f2e964b6a03d50c Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 31 Dec 2015 10:46:40 +0100 Subject: improved coding style diff --git a/src/helsinki.at/rhimport/conf.go b/src/helsinki.at/rhimport/conf.go index 5f22782..d628563 100644 --- a/src/helsinki.at/rhimport/conf.go +++ b/src/helsinki.at/rhimport/conf.go @@ -39,15 +39,15 @@ type Config struct { configfile string RDXportEndpoint string TempDir string - db_host string - db_user string - db_passwd string - db_db string + dbHost string + dbUser string + dbPasswd string + dbDb string LocalFetchDir string ImportParamDefaults } -func get_ini_value(file ini.File, section string, key string, dflt string) string { +func getIniValue(file ini.File, section string, key string, dflt string) string { value, ok := file.Get(section, key) if ok { return value @@ -55,28 +55,28 @@ func get_ini_value(file ini.File, section string, key string, dflt string) strin return dflt } -func (self *Config) read_config_file() error { +func (self *Config) readConfigFile() error { file, err := ini.LoadFile(self.configfile) if err != nil { return err } - self.db_host = get_ini_value(file, "mySQL", "Hostname", "localhost") - self.db_user = get_ini_value(file, "mySQL", "Loginname", "rivendell") - self.db_passwd = get_ini_value(file, "mySQL", "Password", "letmein") - self.db_db = get_ini_value(file, "mySQL", "Database", "rivendell") + self.dbHost = getIniValue(file, "mySQL", "Hostname", "localhost") + self.dbUser = getIniValue(file, "mySQL", "Loginname", "rivendell") + self.dbPasswd = getIniValue(file, "mySQL", "Password", "letmein") + self.dbDb = getIniValue(file, "mySQL", "Database", "rivendell") return nil } -func NewConfig(configfile, rdxport_endpoint, temp_dir, local_fetch_dir *string) (conf *Config, err error) { +func NewConfig(configfile, rdxportEndpoint, tempDir, localFetchDir *string) (conf *Config, err error) { conf = new(Config) conf.configfile = *configfile - if err = conf.read_config_file(); err != nil { + if err = conf.readConfigFile(); err != nil { return } - conf.RDXportEndpoint = *rdxport_endpoint - conf.TempDir = *temp_dir - conf.LocalFetchDir = *local_fetch_dir + conf.RDXportEndpoint = *rdxportEndpoint + conf.TempDir = *tempDir + conf.LocalFetchDir = *localFetchDir conf.ImportParamDefaults.Channels = 2 conf.ImportParamDefaults.NormalizationLevel = -12 conf.ImportParamDefaults.AutotrimLevel = 0 diff --git a/src/helsinki.at/rhimport/core.go b/src/helsinki.at/rhimport/core.go index 3b8280a..1824db1 100644 --- a/src/helsinki.at/rhimport/core.go +++ b/src/helsinki.at/rhimport/core.go @@ -46,10 +46,10 @@ var ( func init() { curl.GlobalInit(curl.GLOBAL_ALL) - fetcher_init() + fetcherInit() } -type ImportProgressCB func(step int, step_name string, progress float64, userdata interface{}) bool +type ImportProgressCB func(step int, stepName string, progress float64, userdata interface{}) bool type ImportContext struct { conf *Config diff --git a/src/helsinki.at/rhimport/fetcher.go b/src/helsinki.at/rhimport/fetcher.go index f1bbb5e..55b814c 100644 --- a/src/helsinki.at/rhimport/fetcher.go +++ b/src/helsinki.at/rhimport/fetcher.go @@ -91,7 +91,7 @@ func curlWriteCallback(ptr []byte, userdata interface{}) bool { return true } -func FetchFileCurl(ctx *ImportContext, res *FetchResult, uri *url.URL) (err error) { +func fetchFileCurl(ctx *ImportContext, res *FetchResult, uri *url.URL) (err error) { rhl.Printf("curl-based fetcher called for '%s'", ctx.SourceUri) easy := curl.EasyInit() @@ -155,7 +155,7 @@ func FetchFileCurl(ctx *ImportContext, res *FetchResult, uri *url.URL) (err erro return } -func FetchFileLocal(ctx *ImportContext, res *FetchResult, uri *url.URL) (err error) { +func fetchFileLocal(ctx *ImportContext, res *FetchResult, uri *url.URL) (err error) { rhl.Printf("Local fetcher called for '%s'", ctx.SourceUri) if ctx.ProgressCallBack != nil { if keep := ctx.ProgressCallBack(1, "fetching", 0.0, ctx.ProgressCallBackData); !keep { @@ -192,7 +192,7 @@ func FetchFileLocal(ctx *ImportContext, res *FetchResult, uri *url.URL) (err err return } -func FetchFileFake(ctx *ImportContext, res *FetchResult, uri *url.URL) error { +func fetchFileFake(ctx *ImportContext, res *FetchResult, uri *url.URL) error { rhdl.Printf("Fake fetcher for '%s'", ctx.SourceUri) if duration, err := strconv.ParseUint(uri.Host, 10, 32); err != nil { @@ -234,28 +234,28 @@ type FetchFunc func(*ImportContext, *FetchResult, *url.URL) (err error) // home:// ????? var ( fetchers = map[string]FetchFunc{ - "local": FetchFileLocal, - "fake": FetchFileFake, + "local": fetchFileLocal, + "fake": fetchFileFake, } - curl_protos = map[string]bool{ + curlProtos = map[string]bool{ "http": false, "https": false, "ftp": false, "ftps": false, } ) -func fetcher_init() { +func fetcherInit() { info := curl.VersionInfo(curl.VERSION_FIRST) protos := info.Protocols for _, proto := range protos { - if _, ok := curl_protos[proto]; ok { + if _, ok := curlProtos[proto]; ok { rhdl.Printf("curl: enabling protocol %s", proto) - fetchers[proto] = FetchFileCurl - curl_protos[proto] = true + fetchers[proto] = fetchFileCurl + curlProtos[proto] = true } else { rhdl.Printf("curl: ignoring protocol %s", proto) } } - for proto, enabled := range curl_protos { + for proto, enabled := range curlProtos { if !enabled { rhl.Printf("curl: protocol %s is disabled because the installed library version doesn't support it!", proto) } diff --git a/src/helsinki.at/rhimport/importer.go b/src/helsinki.at/rhimport/importer.go index abc99e8..e4f979f 100644 --- a/src/helsinki.at/rhimport/importer.go +++ b/src/helsinki.at/rhimport/importer.go @@ -50,8 +50,8 @@ func (self *ImportResult) fromRDWebResult(rdres *RDWebResult) { } } -func add_cart(ctx *ImportContext, res *ImportResult) (err error) { - rhdl.Printf("importer: add_cart() called for cart: %d", ctx.Cart) +func addCart(ctx *ImportContext, res *ImportResult) (err error) { + rhdl.Printf("importer: addCart() called for cart: %d", ctx.Cart) if ctx.GroupName == "" { if err = ctx.getGroupOfCart(); err != nil { @@ -85,7 +85,7 @@ func add_cart(ctx *ImportContext, res *ImportResult) (err error) { w.Close() var resp *http.Response - if resp, err = send_post_request(ctx.conf.RDXportEndpoint, &b, w.FormDataContentType()); err != nil { + if resp, err = sendPostRequest(ctx.conf.RDXportEndpoint, &b, w.FormDataContentType()); err != nil { return } defer resp.Body.Close() @@ -110,8 +110,8 @@ func add_cart(ctx *ImportContext, res *ImportResult) (err error) { return } -func add_cut(ctx *ImportContext, res *ImportResult) (err error) { - rhdl.Printf("importer: add_cut() called for cart/cut: %d/%d", ctx.Cart, ctx.Cut) +func addCut(ctx *ImportContext, res *ImportResult) (err error) { + rhdl.Printf("importer: addCut() called for cart/cut: %d/%d", ctx.Cart, ctx.Cut) var b bytes.Buffer w := multipart.NewWriter(&b) @@ -130,7 +130,7 @@ func add_cut(ctx *ImportContext, res *ImportResult) (err error) { w.Close() var resp *http.Response - if resp, err = send_post_request(ctx.conf.RDXportEndpoint, &b, w.FormDataContentType()); err != nil { + if resp, err = sendPostRequest(ctx.conf.RDXportEndpoint, &b, w.FormDataContentType()); err != nil { return } defer resp.Body.Close() @@ -157,8 +157,8 @@ func add_cut(ctx *ImportContext, res *ImportResult) (err error) { return } -func remove_cart(ctx *ImportContext, res *ImportResult) (err error) { - rhdl.Printf("importer: remove_cart() called for cart: %d", ctx.Cart) +func removeCart(ctx *ImportContext, res *ImportResult) (err error) { + rhdl.Printf("importer: removeCart() called for cart: %d", ctx.Cart) var b bytes.Buffer w := multipart.NewWriter(&b) @@ -177,7 +177,7 @@ func remove_cart(ctx *ImportContext, res *ImportResult) (err error) { w.Close() var resp *http.Response - if resp, err = send_post_request(ctx.conf.RDXportEndpoint, &b, w.FormDataContentType()); err != nil { + if resp, err = sendPostRequest(ctx.conf.RDXportEndpoint, &b, w.FormDataContentType()); err != nil { return } defer resp.Body.Close() @@ -191,8 +191,8 @@ func remove_cart(ctx *ImportContext, res *ImportResult) (err error) { return } -func remove_cut(ctx *ImportContext, res *ImportResult) (err error) { - rhdl.Printf("importer: remove_cut() called for cart/cut: %d/%d", ctx.Cart, ctx.Cut) +func removeCut(ctx *ImportContext, res *ImportResult) (err error) { + rhdl.Printf("importer: removeCut() called for cart/cut: %d/%d", ctx.Cart, ctx.Cut) var b bytes.Buffer w := multipart.NewWriter(&b) @@ -214,7 +214,7 @@ func remove_cut(ctx *ImportContext, res *ImportResult) (err error) { w.Close() var resp *http.Response - if resp, err = send_post_request(ctx.conf.RDXportEndpoint, &b, w.FormDataContentType()); err != nil { + if resp, err = sendPostRequest(ctx.conf.RDXportEndpoint, &b, w.FormDataContentType()); err != nil { return } defer resp.Body.Close() @@ -229,7 +229,7 @@ func remove_cut(ctx *ImportContext, res *ImportResult) (err error) { return } -func send_post_request(url string, b *bytes.Buffer, contenttype string) (resp *http.Response, err error) { +func sendPostRequest(url string, b *bytes.Buffer, contenttype string) (resp *http.Response, err error) { var req *http.Request if req, err = http.NewRequest("POST", url, b); err != nil { return @@ -245,7 +245,7 @@ func send_post_request(url string, b *bytes.Buffer, contenttype string) (resp *h return } -func import_audio_create_request(ctx *ImportContext, easy *curl.CURL) (form *curl.Form, err error) { +func importAudioCreateRequest(ctx *ImportContext, easy *curl.CURL) (form *curl.Form, err error) { form = curl.NewForm() if err = form.Add("COMMAND", "2"); err != nil { @@ -282,8 +282,8 @@ func import_audio_create_request(ctx *ImportContext, easy *curl.CURL) (form *cur return } -func import_audio(ctx *ImportContext, res *ImportResult) (err error) { - rhdl.Printf("importer: import_audio() called for cart/cut: %d/%d", ctx.Cart, ctx.Cut) +func importAudio(ctx *ImportContext, res *ImportResult) (err error) { + rhdl.Printf("importer: importAudio() called for cart/cut: %d/%d", ctx.Cart, ctx.Cut) easy := curl.EasyInit() if easy != nil { @@ -293,7 +293,7 @@ func import_audio(ctx *ImportContext, res *ImportResult) (err error) { easy.Setopt(curl.OPT_POST, true) var form *curl.Form - if form, err = import_audio_create_request(ctx, easy); err != nil { + if form, err = importAudioCreateRequest(ctx, easy); err != nil { return } easy.Setopt(curl.OPT_HTTPPOST, form) @@ -350,24 +350,24 @@ func import_audio(ctx *ImportContext, res *ImportResult) (err error) { return } -func add_cart_cut(ctx *ImportContext, res *ImportResult) (err error) { - if err = add_cart(ctx, res); err != nil || res.ResponseCode != http.StatusOK { +func addCartCut(ctx *ImportContext, res *ImportResult) (err error) { + if err = addCart(ctx, res); err != nil || res.ResponseCode != http.StatusOK { return } - if err = add_cut(ctx, res); err != nil || res.ResponseCode != http.StatusOK { - return remove_cart(ctx, &ImportResult{ResponseCode: http.StatusOK}) + if err = addCut(ctx, res); err != nil || res.ResponseCode != http.StatusOK { + return removeCart(ctx, &ImportResult{ResponseCode: http.StatusOK}) } return } -func remove_add_cart_cut(ctx *ImportContext, res *ImportResult) (err error) { - if err = remove_cart(ctx, res); err != nil || (res.ResponseCode != http.StatusOK && res.ResponseCode != http.StatusNotFound) { +func removeAddCartCut(ctx *ImportContext, res *ImportResult) (err error) { + if err = removeCart(ctx, res); err != nil || (res.ResponseCode != http.StatusOK && res.ResponseCode != http.StatusNotFound) { return } - return add_cart_cut(ctx, res) + return addCartCut(ctx, res) } -func is_cart_member_of_show(ctx *ImportContext, res *ImportResult, carts []uint) (found bool) { +func isCartMemberOfShow(ctx *ImportContext, res *ImportResult, carts []uint) (found bool) { if ctx.Cart == 0 { return true } @@ -382,33 +382,33 @@ func is_cart_member_of_show(ctx *ImportContext, res *ImportResult, carts []uint) return false } -func clear_show_carts(ctx *ImportContext, res *ImportResult, carts []uint) (err error) { +func clearShowCarts(ctx *ImportContext, res *ImportResult, carts []uint) (err error) { if ctx.ClearShowCarts { - orig_cart := ctx.Cart + origCart := ctx.Cart for _, cart := range carts { ctx.Cart = cart - if err = remove_cart(ctx, res); err != nil || (res.ResponseCode != http.StatusOK && res.ResponseCode != http.StatusNotFound) { + if err = removeCart(ctx, res); err != nil || (res.ResponseCode != http.StatusOK && res.ResponseCode != http.StatusNotFound) { return } } - ctx.Cart = orig_cart + ctx.Cart = origCart } return } -func add_show_cart_cut(ctx *ImportContext, res *ImportResult, carts []uint) (err error) { - if err = add_cart(ctx, res); err != nil || res.ResponseCode != http.StatusOK { +func addShowCartCut(ctx *ImportContext, res *ImportResult, carts []uint) (err error) { + if err = addCart(ctx, res); err != nil || res.ResponseCode != http.StatusOK { return } for _, cart := range carts { if cart == ctx.Cart { - if err = add_cut(ctx, res); err != nil || res.ResponseCode != http.StatusOK { - return remove_cart(ctx, &ImportResult{ResponseCode: http.StatusOK}) + if err = addCut(ctx, res); err != nil || res.ResponseCode != http.StatusOK { + return removeCart(ctx, &ImportResult{ResponseCode: http.StatusOK}) } return } } - if err = remove_cart(ctx, res); err != nil || res.ResponseCode != http.StatusOK { + if err = removeCart(ctx, res); err != nil || res.ResponseCode != http.StatusOK { return } res.ResponseCode = http.StatusForbidden @@ -416,7 +416,7 @@ func add_show_cart_cut(ctx *ImportContext, res *ImportResult, carts []uint) (err return } -func cleanup_files(ctx *ImportContext) { +func cleanupFiles(ctx *ImportContext) { if ctx.DeleteSourceFile { rhdl.Printf("importer: removing file: %s", ctx.SourceFile) if err := os.Remove(ctx.SourceFile); err != nil { @@ -435,7 +435,7 @@ func cleanup_files(ctx *ImportContext) { } func ImportFile(ctx *ImportContext) (res *ImportResult, err error) { - defer cleanup_files(ctx) + defer cleanupFiles(ctx) rhl.Printf("importer: ImportFile called with: show-id: %d, pool-name: '%s', cart/cut: %d/%d", ctx.ShowId, ctx.GroupName, ctx.Cart, ctx.Cut) @@ -456,22 +456,22 @@ func ImportFile(ctx *ImportContext) (res *ImportResult, err error) { rmCutOnErr := false res = &ImportResult{ResponseCode: http.StatusOK} if ctx.ShowId != 0 { // Import to a show - var show_carts []uint - if show_carts, err = ctx.getShowInfo(); err != nil { + var showCarts []uint + if showCarts, err = ctx.getShowInfo(); err != nil { return } - if !is_cart_member_of_show(ctx, res, show_carts) { + if !isCartMemberOfShow(ctx, res, showCarts) { return } - if err = clear_show_carts(ctx, res, show_carts); err != nil || (res.ResponseCode != http.StatusOK && res.ResponseCode != http.StatusNotFound) { + if err = clearShowCarts(ctx, res, showCarts); err != nil || (res.ResponseCode != http.StatusOK && res.ResponseCode != http.StatusNotFound) { return } if ctx.ClearCart && !ctx.ClearShowCarts { - if err = remove_add_cart_cut(ctx, res); err != nil || res.ResponseCode != http.StatusOK { + if err = removeAddCartCut(ctx, res); err != nil || res.ResponseCode != http.StatusOK { return } } else { - if err = add_show_cart_cut(ctx, res, show_carts); err != nil || res.ResponseCode != http.StatusOK { + if err = addShowCartCut(ctx, res, showCarts); err != nil || res.ResponseCode != http.StatusOK { return } } @@ -480,22 +480,22 @@ func ImportFile(ctx *ImportContext) (res *ImportResult, err error) { if err = ctx.getMusicInfo(); err != nil { return } - if err = add_cart_cut(ctx, res); err != nil || res.ResponseCode != http.StatusOK { + if err = addCartCut(ctx, res); err != nil || res.ResponseCode != http.StatusOK { return } rmCartOnErr = true } else if ctx.Cart != 0 && ctx.Cut == 0 { // Import to Cart if ctx.ClearCart { - if err = remove_add_cart_cut(ctx, res); err != nil || res.ResponseCode != http.StatusOK { + if err = removeAddCartCut(ctx, res); err != nil || res.ResponseCode != http.StatusOK { return } rmCartOnErr = true } else { - if err = add_cut(ctx, res); err != nil { + if err = addCut(ctx, res); err != nil { return } if res.ResponseCode != http.StatusOK { - if err = add_cart_cut(ctx, res); err != nil || res.ResponseCode != http.StatusOK { + if err = addCartCut(ctx, res); err != nil || res.ResponseCode != http.StatusOK { return } rmCartOnErr = true @@ -506,7 +506,7 @@ func ImportFile(ctx *ImportContext) (res *ImportResult, err error) { } if ctx.Cart != 0 && ctx.Cut != 0 { // Import to specific Cut within Cart - if err = import_audio(ctx, res); err != nil || res.ResponseCode != http.StatusOK { + if err = importAudio(ctx, res); err != nil || res.ResponseCode != http.StatusOK { if err != nil { rhl.Printf("Fileimport has failed (Cart/Cut %d/%d): %s", ctx.Cart, ctx.Cut, err) } else { @@ -515,11 +515,11 @@ func ImportFile(ctx *ImportContext) (res *ImportResult, err error) { // Try to clean up after failed import rmres := ImportResult{ResponseCode: http.StatusOK} if rmCartOnErr { - if rerr := remove_cart(ctx, &rmres); rerr != nil { + if rerr := removeCart(ctx, &rmres); rerr != nil { return } } else if rmCutOnErr { - if rerr := remove_cut(ctx, &rmres); rerr != nil { + if rerr := removeCut(ctx, &rmres); rerr != nil { return } } diff --git a/src/helsinki.at/rhimport/rddb.go b/src/helsinki.at/rhimport/rddb.go index 8bec3c0..12bdba3 100644 --- a/src/helsinki.at/rhimport/rddb.go +++ b/src/helsinki.at/rhimport/rddb.go @@ -63,12 +63,12 @@ type getGroupOfCartRequest struct { } type getShowInfoResult struct { - title string - group string - carts []uint - norm_lvl int - trim_lvl int - err error + title string + group string + carts []uint + normLvl int + trimLvl int + err error } type getShowInfoRequest struct { @@ -87,9 +87,9 @@ type checkMusicGroupRequest struct { } type getMusicInfoResult struct { - norm_lvl int - trim_lvl int - err error + normLvl int + trimLvl int + err error } type getMusicInfoRequest struct { @@ -99,7 +99,7 @@ type getMusicInfoRequest struct { type RdDb struct { dbh *sql.DB - password_cache map[string]string + passwordCache map[string]string getPasswordChan chan getPasswordRequest getPasswordStmt *sql.Stmt getGroupOfCartChan chan getGroupOfCartRequest @@ -117,7 +117,7 @@ type RdDb struct { func (self *RdDb) init(conf *Config) (err error) { godrv.Register("SET CHARACTER SET utf8;") - dsn := fmt.Sprintf("tcp:%s:3306*%s/%s/%s", conf.db_host, conf.db_db, conf.db_user, conf.db_passwd) + dsn := fmt.Sprintf("tcp:%s:3306*%s/%s/%s", conf.dbHost, conf.dbDb, conf.dbUser, conf.dbPasswd) if self.dbh, err = sql.Open("mymysql", dsn); err != nil { return } @@ -153,7 +153,7 @@ func (self *RdDb) init(conf *Config) (err error) { func (self *RdDb) getPassword(username string, cached bool) (result getPasswordResult) { if cached { - result.password = self.password_cache[username] + result.password = self.passwordCache[username] } if result.password == "" { @@ -163,7 +163,7 @@ func (self *RdDb) getPassword(username string, cached bool) (result getPasswordR } return } - self.password_cache[username] = result.password + self.passwordCache[username] = result.password } return @@ -175,18 +175,18 @@ func (self *RdDb) getGroupOfCart(cart uint) (result getGroupOfCartResult) { return } defer rows.Close() - size_min := ^uint(0) + sizeMin := ^uint(0) for rows.Next() { var name string - var low_cart, high_cart uint - if result.err = rows.Scan(&name, &low_cart, &high_cart); result.err != nil { + var lowCart, highCart uint + if result.err = rows.Scan(&name, &lowCart, &highCart); result.err != nil { return } - if high_cart >= low_cart { - size := (high_cart - low_cart) + 1 - if size_min > size { + if highCart >= lowCart { + size := (highCart - lowCart) + 1 + if sizeMin > size { result.group = name - size_min = size + sizeMin = size } } } @@ -207,12 +207,12 @@ func (self *RdDb) getLogTableName(log string) (logtable string, err error) { return } -func (self *RdDb) getShowCarts(log string, low_cart, high_cart int) (carts []uint, err error) { +func (self *RdDb) getShowCarts(log string, lowCart, highCart int) (carts []uint, err error) { var logtable string if logtable, err = self.getLogTableName(log); err != nil { return } - q := fmt.Sprintf("select CART_NUMBER from %s where CART_NUMBER >= %d and CART_NUMBER <= %d order by COUNT;", logtable, low_cart, high_cart) + q := fmt.Sprintf("select CART_NUMBER from %s where CART_NUMBER >= %d and CART_NUMBER <= %d order by COUNT;", logtable, lowCart, highCart) var rows *sql.Rows if rows, err = self.dbh.Query(q); err != nil { return @@ -231,17 +231,17 @@ func (self *RdDb) getShowCarts(log string, low_cart, high_cart int) (carts []uin func (self *RdDb) getShowInfo(showid uint) (result getShowInfoResult) { var macros string - var low_cart, high_cart int - result.err = self.getShowInfoStmt.QueryRow(showid).Scan(&result.title, ¯os, &result.group, &result.norm_lvl, &result.trim_lvl, &low_cart, &high_cart) + var lowCart, highCart int + result.err = self.getShowInfoStmt.QueryRow(showid).Scan(&result.title, ¯os, &result.group, &result.normLvl, &result.trimLvl, &lowCart, &highCart) if result.err != nil { if result.err == sql.ErrNoRows { result.err = fmt.Errorf("show '%d' not found", showid) } return } - result.norm_lvl /= 100 - result.trim_lvl /= 100 - result.carts, result.err = self.getShowCarts(showMacroRe.FindStringSubmatch(macros)[1], low_cart, high_cart) + result.normLvl /= 100 + result.trimLvl /= 100 + result.carts, result.err = self.getShowCarts(showMacroRe.FindStringSubmatch(macros)[1], lowCart, highCart) return } @@ -259,7 +259,7 @@ func (self *RdDb) checkMusicGroup(group string) (result checkMusicGroupResult) { } func (self *RdDb) getMusicInfo(group string) (result getMusicInfoResult) { - result.err = self.getMusicInfoStmt.QueryRow(group).Scan(&result.norm_lvl, &result.trim_lvl) + result.err = self.getMusicInfoStmt.QueryRow(group).Scan(&result.normLvl, &result.trimLvl) if result.err != nil { if result.err == sql.ErrNoRows { result.err = fmt.Errorf("music pool '%s' not found", group) @@ -301,14 +301,14 @@ type RdDbChan struct { } func (self *RdDbChan) GetPassword(username string, cached bool) (string, error) { - res_ch := make(chan getPasswordResult) + resCh := make(chan getPasswordResult) req := getPasswordRequest{} req.username = username req.cached = cached - req.response = res_ch + req.response = resCh self.getPasswordChan <- req - res := <-res_ch + res := <-resCh if res.err != nil { return "", res.err } @@ -319,14 +319,14 @@ func (self *RdDbChan) CheckPassword(username, password string) (bool, error) { cached := true for { - res_ch := make(chan getPasswordResult) + resCh := make(chan getPasswordResult) req := getPasswordRequest{} req.username = username req.cached = cached - req.response = res_ch + req.response = resCh self.getPasswordChan <- req - res := <-res_ch + res := <-resCh if res.err != nil { return false, res.err } @@ -343,13 +343,13 @@ func (self *RdDbChan) CheckPassword(username, password string) (bool, error) { } func (self *RdDbChan) GetGroupOfCart(cart uint) (string, error) { - res_ch := make(chan getGroupOfCartResult) + resCh := make(chan getGroupOfCartResult) req := getGroupOfCartRequest{} req.cart = cart - req.response = res_ch + req.response = resCh self.getGroupOfCartChan <- req - res := <-res_ch + res := <-resCh if res.err != nil { return "", res.err } @@ -357,27 +357,27 @@ func (self *RdDbChan) GetGroupOfCart(cart uint) (string, error) { } func (self *RdDbChan) GetShowInfo(showid uint) (string, int, int, []uint, error) { - res_ch := make(chan getShowInfoResult) + resCh := make(chan getShowInfoResult) req := getShowInfoRequest{} req.showid = showid - req.response = res_ch + req.response = resCh self.getShowInfoChan <- req - res := <-res_ch + res := <-resCh if res.err != nil { return "", 0, 0, nil, res.err } - return res.group, res.norm_lvl, res.trim_lvl, res.carts, nil + return res.group, res.normLvl, res.trimLvl, res.carts, nil } func (self *RdDbChan) CheckMusicGroup(groupname string) (bool, error) { - res_ch := make(chan checkMusicGroupResult) + resCh := make(chan checkMusicGroupResult) req := checkMusicGroupRequest{} req.group = groupname - req.response = res_ch + req.response = resCh self.checkMusicGroupChan <- req - res := <-res_ch + res := <-resCh if res.err != nil { return false, res.err } @@ -385,17 +385,17 @@ func (self *RdDbChan) CheckMusicGroup(groupname string) (bool, error) { } func (self *RdDbChan) GetMusicInfo(groupname string) (int, int, error) { - res_ch := make(chan getMusicInfoResult) + resCh := make(chan getMusicInfoResult) req := getMusicInfoRequest{} req.group = groupname - req.response = res_ch + req.response = resCh self.getMusicInfoChan <- req - res := <-res_ch + res := <-resCh if res.err != nil { return 0, 0, res.err } - return res.norm_lvl, res.trim_lvl, nil + return res.normLvl, res.trimLvl, nil } func (self *RdDb) GetInterface() *RdDbChan { @@ -439,7 +439,7 @@ func NewRdDb(conf *Config) (db *RdDb, err error) { db.quit = make(chan bool) db.done = make(chan bool) - db.password_cache = make(map[string]string) + db.passwordCache = make(map[string]string) db.getPasswordChan = make(chan getPasswordRequest, 10) db.getGroupOfCartChan = make(chan getGroupOfCartRequest, 10) db.getShowInfoChan = make(chan getShowInfoRequest, 10) diff --git a/src/helsinki.at/rhimport/session.go b/src/helsinki.at/rhimport/session.go index 36e7938..82ab3cf 100644 --- a/src/helsinki.at/rhimport/session.go +++ b/src/helsinki.at/rhimport/session.go @@ -92,13 +92,13 @@ type sessionAddDoneHandlerRequest struct { response chan<- sessionAddDoneHandlerResponse } -func session_progress_callback(step int, step_name string, progress float64, userdata interface{}) bool { +func sessionProgressCallback(step int, stepName string, progress float64, userdata interface{}) bool { out := userdata.(chan<- ProgressData) - out <- ProgressData{step, step_name, progress} + out <- ProgressData{step, stepName, progress} return true } -func session_import_run(ctx ImportContext, done chan<- ImportResult) { +func sessionImportRun(ctx ImportContext, done chan<- ImportResult) { if err := ctx.SanityCheck(); err != nil { done <- ImportResult{http.StatusBadRequest, err.Error(), 0, 0} return @@ -122,10 +122,10 @@ func session_import_run(ctx ImportContext, done chan<- ImportResult) { } func (self *Session) run(timeout time.Duration) { - self.ctx.ProgressCallBack = session_progress_callback + self.ctx.ProgressCallBack = sessionProgressCallback self.ctx.ProgressCallBackData = (chan<- ProgressData)(self.progressIntChan) self.ctx.Cancel = self.cancelIntChan - go session_import_run(self.ctx, self.doneIntChan) + go sessionImportRun(self.ctx, self.doneIntChan) self.state = SESSION_RUNNING self.timer.Reset(timeout) return @@ -247,37 +247,40 @@ func (self *SessionChan) Cancel() { } func (self *SessionChan) AddProgressHandler(userdata interface{}, cb ImportProgressCB) error { - res_ch := make(chan sessionAddProgressHandlerResponse) + resCh := make(chan sessionAddProgressHandlerResponse) req := sessionAddProgressHandlerRequest{} req.userdata = userdata req.callback = cb - req.response = res_ch + req.response = resCh select { case self.addProgressChan <- req: default: return fmt.Errorf("session is about to be closed/removed") } - res := <-res_ch + res := <-resCh return res.err } func (self *SessionChan) AddDoneHandler(userdata interface{}, cb func(ImportResult, interface{}) bool) error { - res_ch := make(chan sessionAddDoneHandlerResponse) + resCh := make(chan sessionAddDoneHandlerResponse) req := sessionAddDoneHandlerRequest{} req.userdata = userdata req.callback = cb - req.response = res_ch + req.response = resCh select { case self.addDoneChan <- req: default: return fmt.Errorf("session is about to be closed/removed") } - res := <-res_ch + res := <-resCh return res.err } +// ********************************************************* +// Semi-Public Interface (only used by sessionStore) + func (self *Session) getInterface() *SessionChan { ch := &SessionChan{} ch.runChan = self.runChan @@ -287,7 +290,7 @@ func (self *Session) getInterface() *SessionChan { return ch } -func (self *Session) Cleanup() { +func (self *Session) cleanup() { self.quit <- true rhdl.Printf("waiting for session to close") <-self.done @@ -306,7 +309,7 @@ func (self *Session) Cleanup() { rhdl.Printf("session is now cleaned up") } -func NewSession(ctx *ImportContext, removeFunc func()) (session *Session) { +func newSession(ctx *ImportContext, removeFunc func()) (session *Session) { session = new(Session) session.state = SESSION_NEW session.removeFunc = removeFunc diff --git a/src/helsinki.at/rhimport/session_store.go b/src/helsinki.at/rhimport/session_store.go index 9566293..bb4043b 100644 --- a/src/helsinki.at/rhimport/session_store.go +++ b/src/helsinki.at/rhimport/session_store.go @@ -131,7 +131,7 @@ func (self *SessionStore) new(ctx *ImportContext, refId string) (resp newSession } ctx.conf = self.conf ctx.rddb = self.rddb - s := &SessionStoreElement{NewSession(ctx, func() { self.GetInterface().Remove(ctx.UserName, resp.id) }), refId} + s := &SessionStoreElement{newSession(ctx, func() { self.GetInterface().Remove(ctx.UserName, resp.id) }), refId} self.store[ctx.UserName][resp.id] = s resp.session = self.store[ctx.UserName][resp.id].s.getInterface() rhdl.Printf("SessionStore: created session for '%s' -> %s", ctx.UserName, resp.id) @@ -179,7 +179,7 @@ func (self *SessionStore) remove(user, id string) (resp removeSessionResponse) { resp.responsecode = http.StatusOK resp.errorstring = "OK" if session, exists := self.store[user][id]; exists { - go session.s.Cleanup() // cleanup could take a while -> don't block all the other stuff + go session.s.cleanup() // cleanup could take a while -> don't block all the other stuff delete(self.store[user], id) rhdl.Printf("SessionStore: removed session '%s/%s'", user, id) if userstore, exists := self.store[user]; exists { @@ -224,51 +224,51 @@ type SessionStoreChan struct { } func (self *SessionStoreChan) New(ctx *ImportContext, refId string) (string, *SessionChan, int, string) { - res_ch := make(chan newSessionResponse) + resCh := make(chan newSessionResponse) req := newSessionRequest{} req.ctx = ctx req.refId = refId - req.response = res_ch + req.response = resCh self.newChan <- req - res := <-res_ch + res := <-resCh return res.id, res.session, res.responsecode, res.errorstring } func (self *SessionStoreChan) Get(user, id string) (*SessionChan, string, int, string) { - res_ch := make(chan getSessionResponse) + resCh := make(chan getSessionResponse) req := getSessionRequest{} req.user = user req.id = id - req.response = res_ch + req.response = resCh self.getChan <- req - res := <-res_ch + res := <-resCh return res.session, res.refId, res.responsecode, res.errorstring } func (self *SessionStoreChan) List(user, password string, trusted bool) (map[string]string, int, string) { - res_ch := make(chan listSessionsResponse) + resCh := make(chan listSessionsResponse) req := listSessionsRequest{} req.user = user req.password = password req.trusted = trusted - req.response = res_ch + req.response = resCh self.listChan <- req - res := <-res_ch + res := <-resCh return res.sessions, res.responsecode, res.errorstring } func (self *SessionStoreChan) Remove(user, id string) (int, string) { - res_ch := make(chan removeSessionResponse) + resCh := make(chan removeSessionResponse) req := removeSessionRequest{} req.user = user req.id = id - req.response = res_ch + req.response = resCh self.removeChan <- req - res := <-res_ch + res := <-resCh return res.responsecode, res.errorstring } -- cgit v0.10.2