Skip to content

Commit 6818ec9

Browse files
refactor: format code.
1 parent 5aff208 commit 6818ec9

File tree

5 files changed

+13
-4
lines changed

5 files changed

+13
-4
lines changed

gotty/backend/localcommand/factory.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@ import (
77
"github.com/KubeOperator/webkubectl/gotty/server"
88
)
99

10+
//Options : close options
1011
type Options struct {
1112
CloseSignal int `hcl:"close_signal" flagName:"close-signal" flagSName:"" flagDescribe:"Signal sent to the command process when gotty close it (default: SIGHUP)" default:"1"`
1213
CloseTimeout int `hcl:"close_timeout" flagName:"close-timeout" flagSName:"" flagDescribe:"Time in seconds to force kill process after client is disconnected (default: -1)" default:"-1"`
1314
}
1415

16+
//Factory : command factory
1517
type Factory struct {
1618
command string
1719
argv []string
1820
options *Options
1921
opts []Option
2022
}
2123

24+
//NewFactory : create a new factory
2225
func NewFactory(command string, argv []string, options *Options) (*Factory, error) {
2326
opts := []Option{WithCloseSignal(syscall.Signal(options.CloseSignal))}
2427
if options.CloseTimeout >= 0 {
@@ -33,10 +36,12 @@ func NewFactory(command string, argv []string, options *Options) (*Factory, erro
3336
}, nil
3437
}
3538

39+
//Name : get name of factory
3640
func (factory *Factory) Name() string {
3741
return "local command"
3842
}
3943

44+
//New : create a new slave
4045
func (factory *Factory) New(params map[string][]string) (server.Slave, error) {
4146
argv := make([]string, len(factory.argv))
4247
copy(argv, factory.argv)

gotty/pkg/randomstring/generate.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import (
66
"strconv"
77
)
88

9+
//Generate a random string in specified length
910
func Generate(length int) string {
1011
const base = 36
1112
size := big.NewInt(base)
1213
n := make([]byte, length)
13-
for i, _ := range n {
14+
for i := range n {
1415
c, _ := rand.Int(rand.Reader, size)
1516
n[i] = strconv.FormatInt(c.Int64(), base)[0]
1617
}

gotty/server/handlers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func (server *Server) processWSConn(ctx context.Context, conn *websocket.Conn) e
153153
[]string{"server", "master", "slave"},
154154
map[string]map[string]interface{}{
155155
"server": server.options.TitleVariables,
156-
"master": map[string]interface{}{
156+
"master": {
157157
"remote_addr": conn.RemoteAddr(),
158158
},
159159
"slave": slave.WindowTitleVariables(),
@@ -204,7 +204,7 @@ func (server *Server) handleIndex(w http.ResponseWriter, r *http.Request) {
204204
[]string{"server", "master"},
205205
map[string]map[string]interface{}{
206206
"server": server.options.TitleVariables,
207-
"master": map[string]interface{}{
207+
"master": {
208208
"remote_addr": r.RemoteAddr,
209209
},
210210
},

gotty/webtty/webtty.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func (wt *WebTTY) handleMasterReadEvent(data []byte) error {
219219

220220
case Ping:
221221
err := wt.masterWrite([]byte{Pong})
222-
wt.lastPingTime = time.Now();
222+
wt.lastPingTime = time.Now()
223223
if err != nil {
224224
return errors.Wrapf(err, "failed to return Pong message to master")
225225
}

gotty/webtty/webtty_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ func TestWriteFromConn(t *testing.T) {
120120
// ping
121121
message = []byte("1\n") // line buffered canonical mode
122122
n, err = connOutPipeWriter.Write(message)
123+
if err != nil {
124+
t.Fatalf("Unexpected error from Write(): %s", err)
125+
}
123126
if n != len(message) {
124127
t.Fatalf("Write() accepted `%d` for message `%s`", n, message)
125128
}

0 commit comments

Comments
 (0)