Skip to content

Commit f4157b5

Browse files
committed
Add Go documents
1 parent 2847f41 commit f4157b5

File tree

6 files changed

+26
-32
lines changed

6 files changed

+26
-32
lines changed

builder.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"strings"
99
)
1010

11-
// Builder ...
11+
// Builder is a interface for the build process
1212
type Builder interface {
1313
Build() error
1414
Binary() string
@@ -22,7 +22,7 @@ type builder struct {
2222
buildArgs []string
2323
}
2424

25-
// NewBuilder ...
25+
// NewBuilder creates a new builder
2626
func NewBuilder(dir string, bin string, wd string, buildArgs []string) Builder {
2727
// resolve bin name by current folder name
2828
if bin == "" {
@@ -40,12 +40,12 @@ func NewBuilder(dir string, bin string, wd string, buildArgs []string) Builder {
4040
return &builder{dir: dir, binary: bin, wd: wd, buildArgs: buildArgs}
4141
}
4242

43-
// Binary ...
43+
// Binary returns its build binary's path
4444
func (b *builder) Binary() string {
4545
return b.binary
4646
}
4747

48-
// Build ...
48+
// Build the Golang project set for this builder
4949
func (b *builder) Build() error {
5050
logger.Info("Building program")
5151
args := append([]string{"go", "build", "-o", filepath.Join(b.wd, b.binary)}, b.buildArgs...)

loggger.go

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,62 +7,55 @@ import (
77
"github.com/fatih/color"
88
)
99

10-
// Logger ..
10+
// Logger used by gaper
1111
type Logger struct {
1212
verbose bool
1313
logDebug *log.Logger
14-
logWarn *log.Logger
1514
logInfo *log.Logger
1615
logError *log.Logger
1716
}
1817

19-
// NewLogger ...
18+
// NewLogger creates a new logger
2019
func NewLogger(prefix string) *Logger {
2120
prefix = "[" + prefix + "] "
2221
return &Logger{
2322
verbose: false,
2423
logDebug: log.New(os.Stdout, prefix, 0),
25-
logWarn: log.New(os.Stdout, color.YellowString(prefix), 0),
2624
logInfo: log.New(os.Stdout, color.CyanString(prefix), 0),
2725
logError: log.New(os.Stdout, color.RedString(prefix), 0),
2826
}
2927
}
3028

31-
// Verbose ...
29+
// Verbose toggle this logger verbosity
3230
func (l *Logger) Verbose(verbose bool) {
3331
l.verbose = verbose
3432
}
3533

36-
// Debug ...
34+
// Debug logs a debug message
3735
func (l *Logger) Debug(v ...interface{}) {
3836
if l.verbose {
3937
l.logDebug.Println(v...)
4038
}
4139
}
4240

43-
// Debugf ...
41+
// Debugf logs a debug message with format
4442
func (l *Logger) Debugf(format string, v ...interface{}) {
4543
if l.verbose {
4644
l.logDebug.Printf(format, v...)
4745
}
4846
}
4947

50-
// Warn ...
51-
func (l *Logger) Warn(v ...interface{}) {
52-
l.logWarn.Println(v...)
53-
}
54-
55-
// Info ...
48+
// Info logs a info message
5649
func (l *Logger) Info(v ...interface{}) {
5750
l.logInfo.Println(v...)
5851
}
5952

60-
// Error ...
53+
// Error logs an error message
6154
func (l *Logger) Error(v ...interface{}) {
6255
l.logError.Println(v...)
6356
}
6457

65-
// Errorf ...
58+
// Errorf logs and error message with format
6659
func (l *Logger) Errorf(format string, v ...interface{}) {
6760
l.logError.Printf(format, v...)
6861
}

main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Package gaper implements a supervisor restarts a go project
2+
// when it crashes or a watched file changes
13
package main
24

35
import (
@@ -19,7 +21,7 @@ var logger = NewLogger("gaper")
1921
var exitStatusSuccess = 0
2022
var exitStatusError = 1
2123

22-
// Config ...
24+
// Config contains all settings supported by gaper
2325
type Config struct {
2426
BinName string
2527
BuildPath string

main_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package main
22

33
import (
4-
"fmt"
54
"testing"
65
)
76

87
func TestGaper(t *testing.T) {
9-
fmt.Println("Sample test")
8+
// TODO: add test to main file
109
}

runner.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import (
1010
"time"
1111
)
1212

13-
// OSWindows ...
13+
// OSWindows is used to check if current OS is a Windows
1414
const OSWindows = "windows"
1515

1616
// os errors
1717
var errFinished = errors.New("os: process already finished")
1818

19-
// Runner ...
19+
// Runner is a interface for the run process
2020
type Runner interface {
2121
Run() (*exec.Cmd, error)
2222
Kill() error
@@ -35,7 +35,7 @@ type runner struct {
3535
end chan bool // used internally by Kill to wait a process die
3636
}
3737

38-
// NewRunner ...
38+
// NewRunner creates a new runner
3939
func NewRunner(wStdout io.Writer, wStderr io.Writer, bin string, args []string) Runner {
4040
return &runner{
4141
bin: bin,
@@ -48,7 +48,7 @@ func NewRunner(wStdout io.Writer, wStderr io.Writer, bin string, args []string)
4848
}
4949
}
5050

51-
// Run ...
51+
// Run executes the project binary
5252
func (r *runner) Run() (*exec.Cmd, error) {
5353
logger.Info("Starting program")
5454

@@ -63,7 +63,7 @@ func (r *runner) Run() (*exec.Cmd, error) {
6363
return r.command, nil
6464
}
6565

66-
// Kill ...
66+
// Kill the current process running for the Golang project
6767
func (r *runner) Kill() error {
6868
if r.command == nil || r.command.Process == nil {
6969
return nil
@@ -97,12 +97,12 @@ func (r *runner) Kill() error {
9797
return nil
9898
}
9999

100-
// Exited ...
100+
// Exited checks if the process has exited
101101
func (r *runner) Exited() bool {
102102
return r.command != nil && r.command.ProcessState != nil && r.command.ProcessState.Exited()
103103
}
104104

105-
// Errors ...
105+
// Errors get errors occurred during the build
106106
func (r *runner) Errors() chan error {
107107
return r.errors
108108
}

watcher.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var DefaultExtensions = []string{"go"}
1616
// DefaultPoolInterval used by the watcher
1717
var DefaultPoolInterval = 500
1818

19-
// Watcher ...
19+
// Watcher is a interface for the watch process
2020
type Watcher struct {
2121
PollInterval int
2222
WatchItems []string
@@ -26,7 +26,7 @@ type Watcher struct {
2626
Errors chan error
2727
}
2828

29-
// NewWatcher ...
29+
// NewWatcher creates a new watcher
3030
func NewWatcher(pollInterval int, watchItems []string, ignoreItems []string, extensions []string) (*Watcher, error) {
3131
if pollInterval == 0 {
3232
pollInterval = DefaultPoolInterval
@@ -64,7 +64,7 @@ func NewWatcher(pollInterval int, watchItems []string, ignoreItems []string, ext
6464
var startTime = time.Now()
6565
var errDetectedChange = errors.New("done")
6666

67-
// Watch ...
67+
// Watch starts watching for file changes
6868
func (w *Watcher) Watch() {
6969
for {
7070
for i := range w.WatchItems {

0 commit comments

Comments
 (0)