Skip to content

Commit 646152b

Browse files
author
Aaron Schlesinger
committed
fix(*): add docs and other golint fixes
As of these changes, no more golint errors exist
1 parent b93cc16 commit 646152b

15 files changed

Lines changed: 65 additions & 20 deletions

File tree

pkg/builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const (
1919
StatusLocalError
2020
)
2121

22-
// Run starts the Builder service.
22+
// RunBuilder starts the Builder service.
2323
//
2424
// The Builder service is responsible for setting up the local container
2525
// environment and then listening for new builds. The main listening service

pkg/conf/config.go

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

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

pkg/gitreceive/config.go

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

13+
// Config is the envconfig (http://github.com/kelseyhightower/envconfig) compatible struct for the builder's git-receive hook
1314
type Config struct {
1415
// k8s service discovery env vars
1516
ControllerHost string `envconfig:"DEIS_CONTROLLER_SERVICE_HOST" required:"true"`
@@ -35,6 +36,7 @@ type Config struct {
3536
DockerBuilderImage string `envconfig:"DOCKERBUILDER_IMAGE_NAME" default:"quay.io/deisci/dockerbuilder:v2-beta"`
3637
}
3738

39+
// App returns the application name represented by c. The app name is the same as c.Repository with the last '.' and beyond stripped off
3840
func (c Config) App() string {
3941
li := strings.LastIndex(c.Repository, ".")
4042
if li == -1 {

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ 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
2627
func Run(conf *Config, fs sys.FS, env sys.Env) error {
2728
log.Debug("Running git hook")
2829

pkg/gitreceive/storage/client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import (
55
s3 "github.com/minio/minio-go"
66
)
77

8+
// Client is the S3 client combined with the S3 endpoint
89
type Client struct {
910
*s3.Client
11+
// Endpoint is the the endpoint information for the location that the S3 client will access
1012
Endpoint *Endpoint
1113
}
1214

pkg/gitreceive/storage/endpoint.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ type Endpoint struct {
4444
func (e *Endpoint) FullURL() string {
4545
if e.Secure {
4646
return fmt.Sprintf("https://%s", e.URLStr)
47-
} else {
48-
return fmt.Sprintf("http://%s", e.URLStr)
4947
}
48+
return fmt.Sprintf("http://%s", e.URLStr)
5049
}
5150

5251
func getEndpoint(env sys.Env) (*Endpoint, error) {

pkg/gitreceive/storage/interfaces.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type BucketCreator interface {
1111
MakeBucket(bucketName string, acl s3.BucketACL, location string) error
1212
}
1313

14+
// FakeMakeBucketCall represents a single call to MakeBucket on a FakeBucketCreator
1415
type FakeMakeBucketCall struct {
1516
BucketName string
1617
ACL s3.BucketACL
@@ -23,7 +24,7 @@ type FakeBucketCreator struct {
2324
Calls []FakeMakeBucketCall
2425
}
2526

26-
// PutObject is the interface definition
27+
// MakeBucket is the interface definition for BucketCreator
2728
func (f *FakeBucketCreator) MakeBucket(name string, acl s3.BucketACL, location string) error {
2829
f.Calls = append(f.Calls, FakeMakeBucketCall{BucketName: name, ACL: acl, Location: location})
2930
return f.Fn(name, acl, location)
@@ -34,6 +35,7 @@ type ObjectStatter interface {
3435
StatObject(bucketName, objectKey string) (s3.ObjectInfo, error)
3536
}
3637

38+
// FakeStatObjectCall represents a single call to StatObject on the FakeObjectStatter
3739
type FakeStatObjectCall struct {
3840
BucketName string
3941
ObjectKey string
@@ -45,7 +47,7 @@ type FakeObjectStatter struct {
4547
Calls []FakeStatObjectCall
4648
}
4749

48-
// PutObject is the interface definition
50+
// StatObject is the interface definition
4951
func (f *FakeObjectStatter) StatObject(bucketName, objectKey string) (s3.ObjectInfo, error) {
5052
f.Calls = append(f.Calls, FakeStatObjectCall{BucketName: bucketName, ObjectKey: objectKey})
5153
return f.Fn(bucketName, objectKey)
@@ -56,6 +58,7 @@ type ObjectPutter interface {
5658
PutObject(bucketName, objectKey string, reader io.Reader, contentType string) (int64, error)
5759
}
5860

61+
// FakePutObjectCall represents a single call to PutObject on a FakeObjectPutter
5962
type FakePutObjectCall struct {
6063
BucketName string
6164
ObjectKey string
@@ -80,7 +83,7 @@ func (f *FakeObjectPutter) PutObject(bucketName, objectKey string, reader io.Rea
8083
return f.Fn(bucketName, objectKey, reader, contentType)
8184
}
8285

83-
// The s3.Object already satisfies this interface. As long as it has some or all of the functions as s3.Object, it satisfies it. We're making it have all of the functions in this case. You can create a fake object that also has all of these functions.
86+
// Object is a *(github.com/minio/minio-go).Object compatible interface. Currently, ObjectGetter returns these so that FakeObjectGetters can return mock implementations
8487
type Object interface {
8588
// This is called an interface composition - it automatically gives your interface the function in io.Reader (https://godoc.org/io#Reader) and the function in io.Closer (https://godoc.org/io#Closer)
8689
io.ReadCloser
@@ -92,7 +95,7 @@ type Object interface {
9295
Stat() (s3.ObjectInfo, error)
9396
}
9497

95-
// The minio client doesn't already satisfy this interface, because the GetObject func (https://godoc.org/github.com/minio/minio-go#Client.GetObject) doesn't return an Object. Instead, it returns a *s3.Object. We'll create an adapter below
98+
// ObjectGetter is the interface to get an object from object storage. The minio client doesn't already satisfy this interface, because the GetObject func (https://godoc.org/github.com/minio/minio-go#Client.GetObject) doesn't return an Object. Instead, it returns a *s3.Object. Use the RealObjectGetter below to use the minio client
9699
type ObjectGetter interface {
97100
// GetObject is *almost* the same function as the GetObject func in the minio client, but it returns Object instead of *s3.Object
98101
GetObject(string, string) (Object, error)
@@ -103,6 +106,7 @@ type RealObjectGetter struct {
103106
Client *s3.Client
104107
}
105108

109+
// GetObject is the interface implementation for ObjectGetter
106110
func (r *RealObjectGetter) GetObject(bucket, objKey string) (Object, error) {
107111
obj, err := r.Client.GetObject(bucket, objKey)
108112
if err != nil {
@@ -113,6 +117,7 @@ func (r *RealObjectGetter) GetObject(bucket, objKey string) (Object, error) {
113117
return obj, nil
114118
}
115119

120+
// FakeGetObjectCall represents a single call a single call to GetObject on a FakeObjectGetter
116121
type FakeGetObjectCall struct {
117122
BucketName string
118123
ObjectKey string

pkg/gitreceive/storage/object.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@ func ObjectExists(statter ObjectStatter, bucketName, objKey string) (bool, error
3333
return true, nil
3434
}
3535

36+
// UploadObject uploads the contents of readaer to ${bucektName}/${objectKey} using the given putter
3637
func UploadObject(putter ObjectPutter, bucketName, objKey string, reader io.Reader) error {
3738
_, err := putter.PutObject(bucketName, objKey, reader, octetStream)
3839
return err
3940
}
4041

4142
// WaitForObject checks statter for the object at ${bucketName}/${objKey} right away, then at every tick, then once when the timeout is up.
42-
// Returns nil if it finds the object before or at timeout. Otherwise returns an error
43+
// Returns nil if it finds the object before or at timeout. Otherwise returns a non-nil error
4344
func WaitForObject(statter ObjectStatter, bucketName, objKey string, tick, timeout time.Duration) error {
4445
noExist := errors.New("object doesn't exist")
4546
checker := func() error {
@@ -74,6 +75,7 @@ func WaitForObject(statter ObjectStatter, bucketName, objKey string, tick, timeo
7475
}
7576
}
7677

78+
// DownloadObject uses the given getter to download the contents the object at ${bucketName}/${objKey} and returns the object's contents in the given byte slice. Returns nil and the appropriate error if there were problems with the download
7779
func DownloadObject(getter ObjectGetter, bucketName, objKey string) ([]byte, error) {
7880
reader, err := getter.GetObject(bucketName, objKey)
7981
if err != nil {

pkg/gitreceive/storage/slug_builder_info.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,25 @@ func NewSlugBuilderInfo(s3Endpoint *Endpoint, bucket, appName, slugName string,
3232
}
3333
}
3434

35-
func (s SlugBuilderInfo) PushKey() string { return s.pushKey }
36-
func (s SlugBuilderInfo) PushURL() string { return s.pushURL }
37-
func (s SlugBuilderInfo) TarKey() string { return s.tarKey }
38-
func (s SlugBuilderInfo) TarURL() string { return s.tarURL }
35+
// PushKey returns the object storage key that the slug builder will store the slug in. The returned value only contains the path to the folder, not including the final filename.
36+
func (s SlugBuilderInfo) PushKey() string { return s.pushKey }
37+
38+
// PushURL returns the complete object storage URL that the slug builder will store the slug in. The returned value only contains the URL to the folder, not including the final filename.
39+
func (s SlugBuilderInfo) PushURL() string { return s.pushURL }
40+
41+
// TarKey returns the object storage key from which the slug builder will download for the tarball (from which it uses to build the slug). The returned value only contains the path to the folder, not including the final filename.
42+
func (s SlugBuilderInfo) TarKey() string { return s.tarKey }
43+
44+
// TarURL returns the complete object storage URL that the slug builder will download the tarball from. The returned value only contains the URL to the folder, not including the final filename.
45+
func (s SlugBuilderInfo) TarURL() string { return s.tarURL }
46+
47+
// AbsoluteSlugObjectKey returns the PushKey plus the final filename of the slug
3948
func (s SlugBuilderInfo) AbsoluteSlugObjectKey() string { return s.PushKey() + "/" + slugTGZName }
40-
func (s SlugBuilderInfo) AbsoluteProcfileKey() string { return s.PushKey() + "/Procfile" }
49+
50+
// AbsoluteProcfileKey returns the PushKey plus the standard procfile name
51+
func (s SlugBuilderInfo) AbsoluteProcfileKey() string { return s.PushKey() + "/Procfile" }
52+
53+
// AbsoluteSlugURL returns the PushURL plus the final filename of the slug
4154
func (s SlugBuilderInfo) AbsoluteSlugURL() string {
4255
return s.PushURL() + "/" + slugTGZName
4356
}

0 commit comments

Comments
 (0)