From 3fcaf22bbb9425f2f393dcbba492912a8a246f92 Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Wed, 26 Jul 2017 10:26:59 +0100 Subject: A first go at gometalinter :-) --- commits.go | 98 +++++++++++++++++++++++++++++++------------------------------- config.go | 9 ++---- exec.go | 42 +++++++++++++-------------- scorshd.go | 84 +++++++++++++++++++++++++---------------------------- spooler.go | 14 ++++----- types.go | 40 ++++++++++++------------- workers.go | 8 ++--- 7 files changed, 143 insertions(+), 152 deletions(-) diff --git a/commits.go b/commits.go index 6a8e43e..3381a86 100644 --- a/commits.go +++ b/commits.go @@ -2,7 +2,7 @@ package main import ( "fmt" - "github.com/KatolaZ/git2go" + "github.com/libgit2/git2go" "golang.org/x/crypto/openpgp" "gopkg.in/yaml.v2" "log" @@ -11,7 +11,7 @@ import ( // "log" ) -func CommitToString(commit *git.Commit) string { +func commitToString(commit *git.Commit) string { var ret string @@ -25,56 +25,56 @@ func CommitToString(commit *git.Commit) string { } // FIXME: RETURN THE ENTITY PROVIDED BY THE CHECK, OR nil -func check_signature(commit *git.Commit, keyring *openpgp.KeyRing) (signature, signed string, err error) { +func checkSignature(commit *git.Commit, keyring *openpgp.KeyRing) (signature, signed string, err error) { signature, signed, err = commit.ExtractSignature() if err == nil { - _, err_sig := + _, errSig := openpgp.CheckArmoredDetachedSignature(*keyring, strings.NewReader(signed), strings.NewReader(signature)) - if err_sig == nil { + if errSig == nil { debug.log("[commit: %s] Good signature \n", commit.Id()) return signature, signed, nil } - err = err_sig + err = errSig } return "", "", err } -func find_scorsh_message(commit *git.Commit) (string, error) { +func findScorshMessage(commit *git.Commit) (string, error) { sep := "---\n" msg := commit.RawMessage() - debug.log("[find_scorsg_msg] found message:\n%s\n", msg) + debug.log("[findScorshMessage] found message:\n%s\n", msg) // FIXME!!! replace the following with a proper regexp.Match idx := strings.Index(msg, sep) if idx < 0 { - return "", fmt.Errorf("no SCORSH message found\n") + return "", fmt.Errorf("no SCORSH message found") } return msg[idx:], nil } // return a list of keyring names which verify the signature of a given commit -func get_valid_keys(commit *git.Commit, keys *map[string]openpgp.KeyRing) []string { +func getValidKeys(commit *git.Commit, keys *map[string]openpgp.KeyRing) []string { var ret []string - for k_name, k_val := range *keys { - _, _, err := check_signature(commit, &k_val) + for kname, kval := range *keys { + _, _, err := checkSignature(commit, &kval) if err == nil { - ret = append(ret, k_name) + ret = append(ret, kname) } } return ret } -func intersect_keys(ref map[string]bool, keys []string) []string { +func intersectKeys(ref map[string]bool, keys []string) []string { var ret []string @@ -87,23 +87,23 @@ func intersect_keys(ref map[string]bool, keys []string) []string { return ret } -func find_tag_config(tag_name string, w *SCORSHworker) (*SCORSHtag_cfg, bool) { +func findTagConfig(tagName string, w *SCORSHworker) (*SCORSHtagCfg, bool) { for _, c := range w.Tags { - if c.Name == tag_name { + if c.Name == tagName { return &c, true } } return nil, false } -func get_author_email(c *git.Commit) string { +func getAuthorEmail(c *git.Commit) string { sig := c.Author() return sig.Email } -func get_committer_email(c *git.Commit) string { +func getCommitterEmail(c *git.Commit) string { sig := c.Committer() return sig.Email @@ -112,16 +112,16 @@ func get_committer_email(c *git.Commit) string { // walk_commits traverses all the commits between two references, // looking for scorsh commands, and tries to execute those if found -func walk_commits(msg SCORSHmsg, w *SCORSHworker) error { +func walkCommits(msg SCORSHmsg, w *SCORSHworker) error { - var tags SCORSHclient_msg - var commit_msg string + var tags SCORSHclientMsg + var commitMsg string - debug.log("[worker: %s] Inside parse_commits\n", w.Name) + debug.log("[worker: %s] Inside walkCommits\n", w.Name) reponame := msg.Repo - old_rev := msg.Old_rev - new_rev := msg.New_rev + oldRev := msg.OldRev + newRev := msg.NewRev repo, err := git.OpenRepository(reponame) if err != nil { @@ -130,28 +130,28 @@ func walk_commits(msg SCORSHmsg, w *SCORSHworker) error { return SCORSHerr(SCORSH_ERR_NO_REPO) } - old_rev_oid, err := git.NewOid(old_rev) + oldRevOid, err := git.NewOid(oldRev) - oldrev_commit, err := repo.LookupCommit(old_rev_oid) + oldrevCommit, err := repo.LookupCommit(oldRevOid) if err != nil { - fmt.Fprintf(os.Stderr, "Commit: %s does not exist\n", old_rev) + fmt.Fprintf(os.Stderr, "Commit: %s does not exist\n", oldRev) return SCORSHerr(SCORSH_ERR_NO_COMMIT) } - new_rev_oid, err := git.NewOid(new_rev) + newRevOid, err := git.NewOid(newRev) - newrev_commit, err := repo.LookupCommit(new_rev_oid) + newrevCommit, err := repo.LookupCommit(newRevOid) if err != nil { - fmt.Fprintf(os.Stderr, "Commit: %s does not exist\n", new_rev) + fmt.Fprintf(os.Stderr, "Commit: %s does not exist\n", newRev) return SCORSHerr(SCORSH_ERR_NO_COMMIT) } - cur_commit := newrev_commit + curCommit := newrevCommit // FIXME: replace with a queue of commits - for cur_commit.Id().String() != oldrev_commit.Id().String() { + for curCommit.Id().String() != oldrevCommit.Id().String() { - commit, err := repo.LookupCommit(cur_commit.Id()) + commit, err := repo.LookupCommit(curCommit.Id()) if err == nil { // We look for scorsh-tags, and if the commit has any, check if @@ -159,10 +159,10 @@ func walk_commits(msg SCORSHmsg, w *SCORSHworker) error { // that specific scorsh-tag // Check if the commit contains a scorsh command - commit_msg, err = find_scorsh_message(commit) + commitMsg, err = findScorshMessage(commit) if err == nil { // Check if is the comment contains a valid scorsh message - err = yaml.Unmarshal([]byte(commit_msg), &tags) + err = yaml.Unmarshal([]byte(commitMsg), &tags) if err != nil { // no scorsh message found @@ -171,45 +171,45 @@ func walk_commits(msg SCORSHmsg, w *SCORSHworker) error { // there is a scorsh message there so.... // 1) get the list of all the keyrings which verify the message - valid_keys := get_valid_keys(commit, &(w.Keys)) - debug.log("[worker: %s] validated keyrings on commit: %s\n", w.Name, valid_keys) + validKeys := getValidKeys(commit, &(w.Keys)) + debug.log("[worker: %s] validated keyrings on commit: %s\n", w.Name, validKeys) // 2) then for each tag in the message for _, t := range tags.Tags { // a) check that the tag is among those accepted by the worker - tag_cfg, good_tag := find_tag_config(t.Tag, w) - debug.log("[worker: %s] good_tag: %s\n", w.Name, good_tag) + tagCfg, goodTag := findTagConfig(t.Tag, w) + debug.log("[worker: %s] goodTag: %s\n", w.Name, goodTag) - if !good_tag { + if !goodTag { debug.log("[worker: %s] unsupported tag: %s\n", w.Name, t.Tag) continue } // b) check that at least one of the accepted tag keyrings // is in valid_keys - good_keys := intersect_keys(w.TagKeys[t.Tag], valid_keys) != nil - debug.log("[worker: %s] good_keys: %s\n", w.Name, good_keys) + goodKeys := intersectKeys(w.TagKeys[t.Tag], validKeys) != nil + debug.log("[worker: %s] goodKeys: %s\n", w.Name, goodKeys) - if !good_keys { + if !goodKeys { debug.log("[worker: %s] no matching keys for tag: %s\n", w.Name, t.Tag) continue } // c) If everything is OK, execute the tag - if good_tag && good_keys { - env := set_environment(&msg, t.Tag, get_author_email(commit), get_committer_email(commit)) - errs := exec_tag(tag_cfg, t.Args, env) + if goodTag && goodKeys { + env := setEnvironment(&msg, t.Tag, getAuthorEmail(commit), getCommitterEmail(commit)) + errs := execTag(tagCfg, t.Args, env) debug.log("[worker: %s] errors in tag %s: %s\n", w.Name, t.Tag, errs) } } } } else { - log.Printf("[worker: %s] error parsing commit %s: %s", w.Name, cur_commit.Id().String(), err) + log.Printf("[worker: %s] error parsing commit %s: %s", w.Name, curCommit.Id().String(), err) } // FIXME: ADD ALL THE PARENTS TO THE QUEUE OF COMMITS - cur_commit = commit.Parent(0) + curCommit = commit.Parent(0) } else { - fmt.Printf("Commit %x not found!\n", cur_commit.Id()) + fmt.Printf("Commit %x not found!\n", curCommit.Id()) return SCORSHerr(SCORSH_ERR_NO_COMMIT) } } diff --git a/config.go b/config.go index 8cdd172..317940a 100644 --- a/config.go +++ b/config.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "gopkg.in/yaml.v2" "io" "io/ioutil" @@ -11,16 +10,14 @@ import ( // Read a configuration from fname or die -func ReadGlobalConfig(fname string) *SCORSHmaster { +func readGlobalConfig(fname string) *SCORSHmaster { data, err := ioutil.ReadFile(fname) if err != nil { log.Fatal("Error while reading file: ", err) } - var cfg *SCORSHmaster - - cfg = new(SCORSHmaster) + var cfg = new(SCORSHmaster) // Unmarshal the YAML configuration file into a SCORSHcfg structure err = yaml.Unmarshal(data, cfg) @@ -28,7 +25,7 @@ func ReadGlobalConfig(fname string) *SCORSHmaster { log.Fatal("Error while reading configuration: ", err) } - fmt.Printf("%s", cfg) + //fmt.Printf("%s", cfg) if cfg.Logfile != "" { f, err := os.OpenFile(cfg.Logfile, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0600) diff --git a/exec.go b/exec.go index dc7563c..88f878f 100644 --- a/exec.go +++ b/exec.go @@ -11,9 +11,9 @@ import ( "os/exec" ) -func exec_local_file(cmd_url *url.URL, args, env []string) error { +func execLocalFile(cmdURL *url.URL, args, env []string) error { - cmd := exec.Command(cmd_url.Path, args...) + cmd := exec.Command(cmdURL.Path, args...) cmd.Env = env stdout, err := cmd.StdoutPipe() @@ -34,44 +34,42 @@ func exec_local_file(cmd_url *url.URL, args, env []string) error { return err } -func check_hash(file, hash string) error { +func checkHash(file, hash string) error { data, err := ioutil.ReadFile(file) if err != nil { return err } - hash_bytes := sha256.Sum256(data) - computed_hash := fmt.Sprintf("%x", string(hash_bytes[:sha256.Size])) - debug.log("[check_hash] configured hash string: %s\n", hash) - debug.log("[check_hash] computed hash string: %s\n", computed_hash) - if computed_hash == hash { + hashBytes := sha256.Sum256(data) + computedHash := fmt.Sprintf("%x", string(hashBytes[:sha256.Size])) + debug.log("[checkHash] configured hash string: %s\n", hash) + debug.log("[checkHash] computed hash string: %s\n", computedHash) + if computedHash == hash { return nil - } else { - return fmt.Errorf("WARNING!!! HASH MISMATCH FOR %s", file) } - + return fmt.Errorf("WARNING!!! HASH MISMATCH FOR %s", file) } -func exec_url(cmd_url *url.URL, args, env []string) error { +func execURL(cmdURL *url.URL, args, env []string) error { return nil } -func exec_tag(tag *SCORSHtag_cfg, args []string, env []string) []error { +func execTag(tag *SCORSHtagCfg, args []string, env []string) []error { var ret []error for _, c := range tag.Commands { debug.log("[tag: %s] attempting command: %s\n", tag.Name, c.URL) - cmd_url, err := url.Parse(c.URL) + cmdURL, err := url.Parse(c.URL) if err != nil { log.Printf("[tag: %s] error parsing URL: %s", tag.Name, err) } else { - if cmd_url.Scheme == "file" { + if cmdURL.Scheme == "file" { err = nil // if a hash is specified, check that it matches if c.Hash != "" { - err = check_hash(cmd_url.Path, c.Hash) + err = checkHash(cmdURL.Path, c.Hash) } // if the hash does not match, abort the command if err != nil { @@ -80,11 +78,11 @@ func exec_tag(tag *SCORSHtag_cfg, args []string, env []string) []error { continue } else { // finally, the command can be executed - err = exec_local_file(cmd_url, args, env) + err = execLocalFile(cmdURL, args, env) } - } else if cmd_url.Scheme == "http" || cmd_url.Scheme == "https" { - err = exec_url(cmd_url, args, env) + } else if cmdURL.Scheme == "http" || cmdURL.Scheme == "https" { + err = execURL(cmdURL, args, env) } } ret = append(ret, err) @@ -92,13 +90,13 @@ func exec_tag(tag *SCORSHtag_cfg, args []string, env []string) []error { return ret } -func set_environment(msg *SCORSHmsg, tag, author, committer string) []string { +func setEnvironment(msg *SCORSHmsg, tag, author, committer string) []string { env := os.Environ() env = append(env, fmt.Sprintf("SCORSH_REPO=%s", msg.Repo)) env = append(env, fmt.Sprintf("SCORSH_BRANCH=%s", msg.Branch)) - env = append(env, fmt.Sprintf("SCORSH_OLDREV=%s", msg.Old_rev)) - env = append(env, fmt.Sprintf("SCORSH_NEWREV=%s", msg.New_rev)) + env = append(env, fmt.Sprintf("SCORSH_OLDREV=%s", msg.OldRev)) + env = append(env, fmt.Sprintf("SCORSH_NEWREV=%s", msg.NewRev)) env = append(env, fmt.Sprintf("SCORSH_ID=%s", msg.Id)) env = append(env, fmt.Sprintf("SCORSH_TAG=%s", tag)) env = append(env, fmt.Sprintf("SCORSH_AUTHOR=%s", author)) diff --git a/scorshd.go b/scorshd.go index d36b646..c9ad835 100644 --- a/scorshd.go +++ b/scorshd.go @@ -20,31 +20,31 @@ func (d debugging) log(format string, args ...interface{}) { /////////// -var conf_file = flag.String("c", "./scorsh.cfg", "Configuration file for SCORSH") +var confFile = flag.String("c", "./scorsh.cfg", "Configuration file for SCORSH") func SCORSHerr(err int) error { - var err_str string + var errStr string switch err { case SCORSH_ERR_NO_FILE: - err_str = "Invalid file name" + errStr = "Invalid file name" case SCORSH_ERR_KEYRING: - err_str = "Invalid keyring" + errStr = "Invalid keyring" case SCORSH_ERR_NO_REPO: - err_str = "Invalid repository" + errStr = "Invalid repository" case SCORSH_ERR_NO_COMMIT: - err_str = "Invalid commit ID" + errStr = "Invalid commit ID" case SCORSH_ERR_SIGNATURE: - err_str = "Invalid signature" + errStr = "Invalid signature" default: - err_str = "Generic Error" + errStr = "Generic Error" } - return fmt.Errorf("%s", err_str) + return fmt.Errorf("%s", errStr) } -func FindMatchingWorkers(master *SCORSHmaster, msg *SCORSHmsg) []*SCORSHworker { +func findMatchingWorkers(master *SCORSHmaster, msg *SCORSHmsg) []*SCORSHworker { var ret []*SCORSHworker @@ -57,62 +57,58 @@ func FindMatchingWorkers(master *SCORSHmaster, msg *SCORSHmsg) []*SCORSHworker { return ret } -func Master(master *SCORSHmaster) { +func runMaster(master *SCORSHmaster) { // master main loop: - var matching_workers []*SCORSHworker - - matching_workers = make([]*SCORSHworker, len(master.Workers)) - log.Println("[master] Master started ") debug.log("[master] StatusChan: %s\n", master.StatusChan) for { debug.log("[master] Receive loop...\n") select { - case push_msg := <-master.Spooler: + case pushMsg := <-master.Spooler: // here we manage the stuff we receive from the spooler - debug.log("[master] received message: %s\n", push_msg) + debug.log("[master] received message: %s\n", pushMsg) // - lookup the repos map for matching workers - matching_workers = FindMatchingWorkers(master, &push_msg) - debug.log("[master] matching workers: \n%s\n", matching_workers) + matchingWorkers := findMatchingWorkers(master, &pushMsg) + debug.log("[master] matching workers: \n%s\n", matchingWorkers) // add the message to WorkingMsg, if it's not a duplicate! - if _, ok := master.WorkingMsg[push_msg.Id]; ok { - log.Printf("[master] detected duplicate message %s \n", push_msg.Id) + if _, ok := master.WorkingMsg[pushMsg.Id]; ok { + log.Printf("[master] detected duplicate message %s \n", pushMsg.Id) } else { - master.WorkingMsg[push_msg.Id] = 0 + master.WorkingMsg[pushMsg.Id] = 0 // - dispatch the message to all the matching workers - for _, w := range matching_workers { + for _, w := range matchingWorkers { debug.log("[master] sending msg to worker: %s\n", w.Name) // send the message to the worker - w.MsgChan <- push_msg + w.MsgChan <- pushMsg // increase the counter associated to the message - master.WorkingMsg[push_msg.Id] += 1 - debug.log("[master] now WorkingMsg[%s] is: %d\n", push_msg.Id, master.WorkingMsg[push_msg.Id]) + master.WorkingMsg[pushMsg.Id]++ + debug.log("[master] now WorkingMsg[%s] is: %d\n", pushMsg.Id, master.WorkingMsg[pushMsg.Id]) } } - case done_msg := <-master.StatusChan: + case doneMsg := <-master.StatusChan: // Here we manage a status message from a worker - debug.log("[master] received message from StatusChan: %s\n", done_msg) - if _, ok := master.WorkingMsg[done_msg.Id]; ok && master.WorkingMsg[done_msg.Id] > 0 { - master.WorkingMsg[done_msg.Id] -= 1 - if master.WorkingMsg[done_msg.Id] == 0 { - delete(master.WorkingMsg, done_msg.Id) - master.Spooler <- done_msg + debug.log("[master] received message from StatusChan: %s\n", doneMsg) + if _, ok := master.WorkingMsg[doneMsg.Id]; ok && master.WorkingMsg[doneMsg.Id] > 0 { + master.WorkingMsg[doneMsg.Id]-- + if master.WorkingMsg[doneMsg.Id] == 0 { + delete(master.WorkingMsg, doneMsg.Id) + master.Spooler <- doneMsg } } else { - log.Printf("[master] received completion event for non-existing message name: %s\n", done_msg.Id) + log.Printf("[master] received completion event for non-existing message name: %s\n", doneMsg.Id) } } } debug.log("[master] Exiting the for loop, for some mysterious reason...\n") } -func InitMaster() *SCORSHmaster { +func initMaster() *SCORSHmaster { - master := ReadGlobalConfig(*conf_file) + master := readGlobalConfig(*confFile) master.Repos = make(map[string][]*SCORSHworker) master.WorkingMsg = make(map[string]int) @@ -123,15 +119,15 @@ func InitMaster() *SCORSHmaster { debug.log("[InitMaster] StatusChan: %s\n", master.StatusChan) - err_workers := StartWorkers(master) - if err_workers != nil { - log.Fatal("Error starting workers: ", err_workers) + errWorkers := startWorkers(master) + if errWorkers != nil { + log.Fatal("Error starting workers: ", errWorkers) } else { log.Println("Workers started correctly") } - err_spooler := StartSpooler(master) - if err_spooler != nil { - log.Fatal("Error starting spooler: ", err_spooler) + errSpooler := startSpooler(master) + if errSpooler != nil { + log.Fatal("Error starting spooler: ", errSpooler) } return master } @@ -142,9 +138,9 @@ func main() { flag.Parse() - master := InitMaster() + master := initMaster() - go Master(master) + go runMaster(master) // wait indefinitely -- we should implement signal handling... <-done diff --git a/spooler.go b/spooler.go index ccf42dc..b25167b 100644 --- a/spooler.go +++ b/spooler.go @@ -11,9 +11,9 @@ import ( ) // parse a request file and return a SCORSHmessage -func parse_request(fname string, msg *SCORSHmsg) error { +func parseRequest(fname string, msg *SCORSHmsg) error { - debug.log("[parse_request] message at start: %s\n", msg) + debug.log("[parseRequest] message at start: %s\n", msg) data, err := ioutil.ReadFile(fname) if err != nil { @@ -21,15 +21,15 @@ func parse_request(fname string, msg *SCORSHmsg) error { return SCORSHerr(SCORSH_ERR_NO_FILE) } - debug.log("[parse_request] file contains: \n%s\n", data) + debug.log("[parseRequest] file contains: \n%s\n", data) - debug.log("[parse_request] reading message from file: %s\n", fname) + debug.log("[parseRequest] reading message from file: %s\n", fname) err = yaml.Unmarshal([]byte(data), msg) if err != nil { return fmt.Errorf("Error parsing message: %s", err) } - debug.log("[parse_request] got message: %s\n", msg) + debug.log("[parseRequest] got message: %s\n", msg) return nil } @@ -46,7 +46,7 @@ func spooler(watcher *fsnotify.Watcher, master chan SCORSHmsg) { if event.Op == fsnotify.Write { var msg SCORSHmsg debug.log("[spooler] new file %s detected\n", event.Name) - err := parse_request(event.Name, &msg) + err := parseRequest(event.Name, &msg) if err != nil { log.Printf("Invalid packet received. [%s]\n", err) } @@ -71,7 +71,7 @@ func spooler(watcher *fsnotify.Watcher, master chan SCORSHmsg) { } } -func StartSpooler(master *SCORSHmaster) error { +func startSpooler(master *SCORSHmaster) error { watcher, err := fsnotify.NewWatcher() diff --git a/types.go b/types.go index 235ef8d..bbd2ecc 100644 --- a/types.go +++ b/types.go @@ -17,12 +17,12 @@ const ( // the SCORSHmsg type represents messages received from the spool and // sent to workers type SCORSHmsg struct { - Id string `yaml:"m_id"` - Repo string `yaml:"m_repo"` - Branch string `yaml:"m_branch"` - Old_rev string `yaml:"m_oldrev"` - New_rev string `yaml:"m_newrev"` - Path string + Id string `yaml:"m_id"` + Repo string `yaml:"m_repo"` + Branch string `yaml:"m_branch"` + OldRev string `yaml:"m_oldrev"` + NewRev string `yaml:"m_newrev"` + Path string } type SCORSHcmd struct { @@ -30,26 +30,26 @@ type SCORSHcmd struct { Hash string `yaml:"c_hash"` } -type SCORSHtag_cfg struct { +type SCORSHtagCfg struct { Name string `yaml:"t_name"` Keyrings []string `yaml:"t_keyrings"` Commands []SCORSHcmd `yaml:"t_commands"` } // Configuration of a worker -type SCORSHworker_cfg struct { +type SCORSHworkerCfg struct { Name string `yaml:"w_name"` Repos []string `yaml:"w_repos"` Folder string `yaml:"w_folder"` Logfile string `yaml:"w_logfile"` Tagfile string `yaml:"w_tagfile"` // Keyrings []string `yaml:"w_keyrings"` - Tags []SCORSHtag_cfg `yaml:"w_tags"` + Tags []SCORSHtagCfg `yaml:"w_tags"` TagKeys map[string]map[string]bool } // State of a worker -type SCORSHworker_state struct { +type SCORSHworkerState struct { Keys map[string]openpgp.KeyRing MsgChan chan SCORSHmsg StatusChan chan SCORSHmsg @@ -58,12 +58,12 @@ type SCORSHworker_state struct { // The type SCORSHworker represents the configuration and state of a // worker type SCORSHworker struct { - SCORSHworker_cfg `yaml:",inline"` - SCORSHworker_state + SCORSHworkerCfg `yaml:",inline"` + SCORSHworkerState } // Configuration of the master -type SCORSHmaster_cfg struct { +type SCORSHmasterCfg struct { Spooldir string `yaml:"s_spooldir"` Logfile string `yaml:"s_logfile"` LogPrefix string `yaml:"s_logprefix"` @@ -71,7 +71,7 @@ type SCORSHmaster_cfg struct { } // State of the master -type SCORSHmaster_state struct { +type SCORSHmasterState struct { Spooler chan SCORSHmsg StatusChan chan SCORSHmsg Repos map[string][]*SCORSHworker @@ -81,8 +81,8 @@ type SCORSHmaster_state struct { // The type SCORSHmaster represents the configuration and state of the // master type SCORSHmaster struct { - SCORSHmaster_cfg `yaml:",inline"` - SCORSHmaster_state + SCORSHmasterCfg `yaml:",inline"` + SCORSHmasterState } // client commands @@ -92,7 +92,7 @@ type SCORSHtag struct { Args []string `yaml:"s_args"` } -type SCORSHclient_msg struct { +type SCORSHclientMsg struct { Tags []SCORSHtag `yaml:"scorsh"` } @@ -120,8 +120,8 @@ func (msg *SCORSHmsg) String() string { fmt.Fprintf(&buff, "Id: %s\n", msg.Id) fmt.Fprintf(&buff, "Repo: %s\n", msg.Repo) fmt.Fprintf(&buff, "Branch: %s\n", msg.Branch) - fmt.Fprintf(&buff, "Old_Rev: %s\n", msg.Old_rev) - fmt.Fprintf(&buff, "New_rev: %s\n", msg.New_rev) + fmt.Fprintf(&buff, "OldRev: %s\n", msg.OldRev) + fmt.Fprintf(&buff, "Newrev: %s\n", msg.NewRev) fmt.Fprintf(&buff, "Path: %s\n", msg.Path) return buff.String() @@ -141,7 +141,7 @@ func (w *SCORSHworker) String() string { return buff.String() } -func (msg *SCORSHclient_msg) String() string { +func (msg *SCORSHclientMsg) String() string { var buff bytes.Buffer diff --git a/workers.go b/workers.go index 66dc6b0..2562b68 100644 --- a/workers.go +++ b/workers.go @@ -86,7 +86,7 @@ func (w *SCORSHworker) LoadTags() error { } // FIXME--- still needs some work... -func Worker(w *SCORSHworker) { +func runWorker(w *SCORSHworker) { var msg SCORSHmsg @@ -101,7 +101,7 @@ func Worker(w *SCORSHworker) { case msg = <-w.MsgChan: debug.log("[worker: %s] received message %s\n", w.Name, msg.Id) // process message - err := walk_commits(msg, w) + err := walkCommits(msg, w) if err != nil { log.Printf("[worker: %s] error in walk_commits: %s", err) } @@ -113,7 +113,7 @@ func Worker(w *SCORSHworker) { // StartWorkers starts all the workers specified in a given // configuration and fills in the SCORSHmaster struct -func StartWorkers(master *SCORSHmaster) error { +func startWorkers(master *SCORSHmaster) error { num_workers := len(master.Workers) @@ -146,7 +146,7 @@ func StartWorkers(master *SCORSHmaster) error { for _, repo_name := range worker.Repos { master.Repos[repo_name] = append(master.Repos[repo_name], worker) } - go Worker(worker) + go runWorker(worker) <-master.StatusChan } return nil -- cgit v1.2.3