Skip to content

Commit fdb79a9

Browse files
committed
Merge pull request #247 from arschles/fix-golint
fix(*): add godocs and address other golint issues
2 parents b93cc16 + 71980fc commit fdb79a9

29 files changed

Lines changed: 251 additions & 121 deletions

pkg/builder.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Package pkg provides common libraries for the Deis builder.
22
//
3-
// The Deis builder is responsible for packaging Docker images for consumers.
3+
// The Deis builder is responsible for building slugs and docker images for use in the Deis
4+
// on the Deis PaaS platform.
45
package pkg
56

67
import (
@@ -19,7 +20,7 @@ const (
1920
StatusLocalError
2021
)
2122

22-
// Run starts the Builder service.
23+
// RunBuilder starts the Builder service.
2324
//
2425
// The Builder service is responsible for setting up the local container
2526
// environment and then listening for new builds. The main listening service

pkg/cleaner/cleaner.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// Package cleaner is a background process that compares the kubernetes namespace list with the folders in the local git home directory, deleting what's not in the namespace list
1+
// Package cleaner is a background process that compares the kubernetes namespace list with the
2+
// folders in the local git home directory, deleting what's not in the namespace list.
23
package cleaner
34

45
import (
@@ -14,9 +15,11 @@ const (
1415
dotGitSuffix = ".git"
1516
)
1617

17-
// Run starts the deleted app cleaner. This function listens to the Kubernetes event stream for events that indicate namespaces that were `DELETED`.
18+
// Run starts the deleted app cleaner. This function listens to the Kubernetes event stream for
19+
// events that indicate namespaces that were `DELETED`.
1820
// If the namespace name matches a folder on the local filesystem, this func deletes that folder.
19-
// Note that this function blocks until the watcher returned by `nsLister.Watch` is closed, so you should launch it in a goroutine.
21+
// Note that this function blocks until the watcher returned by `nsLister.Watch` is closed, so
22+
// you should launch it in a goroutine.
2023
func Run(gitHome string, nsLister k8s.NamespaceWatcher, fs sys.FS) error {
2124
watcher, err := nsLister.Watch(nil, nil, "")
2225
if err != nil {

pkg/conf/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ const (
1111
builderKeyLocation = "/var/run/secrets/api/auth/builder-key"
1212
)
1313

14+
// EnvConfig is a convenience function to process the envconfig (
15+
// https://github.com/kelseyhightower/envconfig) based configuration environment variables into
16+
// conf. Additional notes:
17+
//
18+
// - appName will be passed as the first parameter to envconfig.Process
19+
// - conf should be a pointer to an envconfig compatible struct. If you'd like to use struct
20+
// tags to customize your struct, see
21+
// https://github.com/kelseyhightower/envconfig#struct-tag-support
1422
func EnvConfig(appName string, conf interface{}) error {
1523
if err := envconfig.Process(appName, conf); err != nil {
1624
return err

pkg/controller/utils.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ const (
1818
portEnvName = "DEIS_CONTROLLER_SERVICE_PORT"
1919
)
2020

21-
// UserInfo represent the required information from a user to make a push and interact with the controller
21+
// UserInfo represents the required information from a user to make a push and interact with the
22+
// controller
2223
type UserInfo struct {
2324
Username string
2425
Key string
@@ -61,7 +62,7 @@ func fingerprint(key ssh.PublicKey) string {
6162
return string(fp)
6263
}
6364

64-
// UserInfoFromKey makes a request to the controller to get the user info from they given key
65+
// UserInfoFromKey makes a request to the controller to get the user info from they given key.
6566
func UserInfoFromKey(key ssh.PublicKey) (*UserInfo, error) {
6667
fp := fingerprint(key)
6768
url, err := controllerURLStr("v2", "hooks", "key", fp)

pkg/git/git.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ import (
2222
"golang.org/x/crypto/ssh"
2323
)
2424

25-
// prereceiveHookTplStr is the template for a pre-receive hook. The following template variables are passed into it:
25+
// prereceiveHookTplStr is the template for a pre-receive hook. The following template variables
26+
// are passed into it:
2627
//
27-
// .GitHome: the path to Git's home directory.
28+
// - .GitHome: the path to Git's home directory
2829
const preReceiveHookTplStr = `#!/bin/bash
2930
strip_remote_prefix() {
3031
stdbuf -i0 -o0 -e0 sed "s/^/"$'\e[1G'"/"

pkg/gitreceive/build.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ func repoCmd(repoDir, first string, others ...string) *exec.Cmd {
2929
return cmd
3030
}
3131

32-
// run prints the command it will execute to the debug log, then runs it and returns the result of run
32+
// run prints the command it will execute to the debug log, then runs it and returns the result
33+
// of run
3334
func run(cmd *exec.Cmd) error {
3435
cmdStr := strings.Join(cmd.Args, " ")
3536
if cmd.Dir != "" {

pkg/gitreceive/config.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const (
1010
objectStorageTick = 500
1111
)
1212

13+
// Config is the envconfig (http://github.com/kelseyhightower/envconfig) compatible struct for the
14+
// builder's git-receive hook.
1315
type Config struct {
1416
// k8s service discovery env vars
1517
ControllerHost string `envconfig:"DEIS_CONTROLLER_SERVICE_HOST" required:"true"`
@@ -35,6 +37,8 @@ type Config struct {
3537
DockerBuilderImage string `envconfig:"DOCKERBUILDER_IMAGE_NAME" default:"quay.io/deisci/dockerbuilder:v2-beta"`
3638
}
3739

40+
// App returns the application name represented by c. The app name is the same as c.Repository
41+
// with the last '.' and beyond stripped off.
3842
func (c Config) App() string {
3943
li := strings.LastIndex(c.Repository, ".")
4044
if li == -1 {
@@ -44,31 +48,31 @@ func (c Config) App() string {
4448
}
4549

4650
// BuilderPodTickDuration returns the size of the interval used to check for
47-
// the end of the execution of a Pod building an application
51+
// the end of the execution of a Pod building an application.
4852
func (c Config) BuilderPodTickDuration() time.Duration {
4953
return time.Duration(time.Duration(c.BuilderPodTickDurationMSec) * time.Millisecond)
5054
}
5155

5256
// BuilderPodWaitDuration returns the maximum time to wait for the end
53-
// of the execution of a Pod building an application
57+
// of the execution of a Pod building an application.
5458
func (c Config) BuilderPodWaitDuration() time.Duration {
5559
return time.Duration(time.Duration(c.BuilderPodWaitDurationMSec) * time.Millisecond)
5660
}
5761

5862
// ObjectStorageTickDuration returns the size of the interval used to check for
59-
// the end of an operation that involves the object storage
63+
// the end of an operation that involves the object storage.
6064
func (c Config) ObjectStorageTickDuration() time.Duration {
6165
return time.Duration(time.Duration(c.ObjectStorageTickDurationMSec) * time.Millisecond)
6266
}
6367

6468
// ObjectStorageWaitDuration returns the maximum time to wait for the end of an
65-
// operation that involves the object storage
69+
// operation that involves the object storage.
6670
func (c Config) ObjectStorageWaitDuration() time.Duration {
6771
return time.Duration(time.Duration(c.ObjectStorageWaitDurationMSec) * time.Millisecond)
6872
}
6973

7074
// CheckDurations checks if ticks for builder and object storage are not bigger
71-
// than the maximum duration. In case of this it will set the tick to the default
75+
// than the maximum duration. In case of this it will set the tick to the default.
7276
func (c *Config) CheckDurations() {
7377
if c.BuilderPodTickDurationMSec >= c.BuilderPodWaitDurationMSec {
7478
c.BuilderPodTickDurationMSec = builderPodTick

pkg/gitreceive/git/sha.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,32 @@ const (
1212

1313
var shaRegex = regexp.MustCompile(`^[\da-f]{40}$`)
1414

15+
// ErrInvalidGitSha is returned by NewSha if the given raw sha is invalid for any reason.
1516
type ErrInvalidGitSha struct {
1617
sha string
1718
}
1819

20+
// Error is the error interface implementation.
1921
func (e ErrInvalidGitSha) Error() string {
2022
return fmt.Sprintf("git sha %s was invalid", e.sha)
2123
}
2224

25+
// SHA is the representaton of a git sha
2326
type SHA struct {
2427
full string
2528
short string
2629
}
2730

31+
// NewSha creates a raw string to a SHA. Returns ErrInvalidGitSha if the sha was invalid.
2832
func NewSha(rawSha string) (*SHA, error) {
2933
if !shaRegex.MatchString(rawSha) {
3034
return nil, ErrInvalidGitSha{sha: rawSha}
3135
}
3236
return &SHA{full: rawSha, short: rawSha[0:8]}, nil
3337
}
3438

35-
func (s SHA) Full() string { return s.full }
39+
// Full returns the full git sha.
40+
func (s SHA) Full() string { return s.full }
41+
42+
// Short returns the first 8 characters of the sha.
3643
func (s SHA) Short() string { return s.short }

pkg/gitreceive/run.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ func readLine(line string) (string, string, string, error) {
2323
return spl[0], spl[1], spl[2], nil
2424
}
2525

26+
// Run runs the git-receive hook. This func is effectively the main for the git-receive hook,
27+
// although it is called from the main in boot.go.
2628
func Run(conf *Config, fs sys.FS, env sys.Env) error {
2729
log.Debug("Running git hook")
2830

pkg/gitreceive/storage/auth.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func (c *creds) isZero() bool {
3131
// getAuth gets storage credentials from accessKeyIDFile and accessSecretKeyFile.
3232
// if a key exists but not a secret, or vice-versa, returns an error.
3333
// if both don't exist returns emptyAuth.
34-
// otherwise returns a valid auth
34+
// otherwise returns a valid auth.
3535
func getAuth(fs sys.FS) (*creds, error) {
3636
accessKeyIDBytes, accessKeyErr := fs.ReadFile(accessKeyIDFile)
3737
accessSecretKeyBytes, accessSecretKeyErr := fs.ReadFile(accessSecretKeyFile)
@@ -50,7 +50,7 @@ func getAuth(fs sys.FS) (*creds, error) {
5050
return &creds{accessKeyID: id, accessKeySecret: secret}, nil
5151
}
5252

53-
// CredsOK checks if the required credentials to make a request exist
53+
// CredsOK checks if the required credentials to make a request exist.
5454
func CredsOK(fs sys.FS) bool {
5555
creds, err := getAuth(fs)
5656
if err != nil {

0 commit comments

Comments
 (0)