Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #68 from vania-pooh/master
Browse files Browse the repository at this point in the history
Minor code style fixes and removed deprecated packages
  • Loading branch information
vania-pooh authored Jan 7, 2024
2 parents 283b5b4 + f139757 commit 7f3f77b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
8 changes: 4 additions & 4 deletions ggr-ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func status(w http.ResponseWriter, r *http.Request) {
select {
case s := <-done:
w.Header().Add("Content-Type", "application/json")
json.NewEncoder(w).Encode(s)
_ = json.NewEncoder(w).Encode(s)
case <-r.Context().Done():
}
}
Expand Down Expand Up @@ -199,11 +199,11 @@ func proxyWS(p string) func(wsconn *websocket.Conn) {
defer conn.Close()
wsconn.PayloadType = websocket.BinaryFrame
go func() {
io.Copy(wsconn, conn)
wsconn.Close()
defer wsconn.Close()
_, _ = io.Copy(wsconn, conn)
log.Printf("[WEBSOCKET] [Closed websocket session to %s] [%s]", u, remote)
}()
io.Copy(conn, wsconn)
_, _ = io.Copy(conn, wsconn)
log.Printf("[WEBSOCKET] [Client disconnected: %s] [%s]", u, remote)
}
}
Expand Down
23 changes: 11 additions & 12 deletions ggr-ui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -65,7 +64,7 @@ func CheckPath(p string) (*url.URL, error) {
}

func ReadResponseBody(r io.Reader) ([]byte, error) {
buf, err := ioutil.ReadAll(r)
buf, err := io.ReadAll(r)
if err != nil {
return nil, fmt.Errorf("read response body: %v", err)
}
Expand Down Expand Up @@ -232,10 +231,10 @@ var (
<-r.Context().Done()
}))
empty = http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, `{"total":1,"used":0,"queued":0,"pending":0,"browsers":{"chrome":{"60.0":{}},"firefox":{"59.0":{}}}}`)
_, _ = fmt.Fprint(w, `{"total":1,"used":0,"queued":0,"pending":0,"browsers":{"chrome":{"60.0":{}},"firefox":{"59.0":{}}}}`)
}))
broken = http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, `{"total":1,"used":0,"queued":0,"pending":0,`)
_, _ = fmt.Fprint(w, `{"total":1,"used":0,"queued":0,"pending":0,`)
}))
)

Expand All @@ -249,49 +248,49 @@ type Case struct {

func TestStatus(t *testing.T) {
cases := []Case{
Case{
{
Name: "ConnectionRefused",
Expected: 0,
Timeout: 100 * time.Millisecond,
Handlers: []http.Handler{nil, nil, nil},
},
Case{
{
Name: "Timeout",
Expected: 0,
Timeout: 100 * time.Millisecond,
Handlers: []http.Handler{silent},
},
Case{
{
Name: "ClientDisconnected",
Expected: 0,
ContextTimeout: 100 * time.Millisecond,
Handlers: []http.Handler{silent},
},
Case{
{
Name: "TwoHostsDown",
Expected: 1,
Handlers: []http.Handler{nil, nil, empty},
},
Case{
{
Name: "TwoHostsBroken",
Expected: 1,
Handlers: []http.Handler{broken, broken, empty},
},
Case{
{
Name: "TwoHostsNoAnswer",
Expected: 1,
Timeout: 100 * time.Millisecond,
Handlers: []http.Handler{silent, silent, empty},
},
Case{
{
Name: "AllHostsUpAndRunning",
Expected: 3,
Handlers: []http.Handler{empty, empty, empty},
},
}
for i, c := range cases {
m := map[string]map[string]*config.Host{
"unknown": map[string]*config.Host{}}
"unknown": {}}
for _, handler := range c.Handlers {
selenoid := NewSelenoid(handler)
if handler != nil {
Expand Down
8 changes: 5 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/xml"
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -51,7 +50,7 @@ func configure() error {
}
newHosts := make(map[string]map[string]*config.Host)
for _, fn := range files {
file, err := ioutil.ReadFile(fn)
file, err := os.ReadFile(fn)
if err != nil {
log.Printf("[INIT] [Error reading configuration file %s: %v]", fn, err)
continue
Expand Down Expand Up @@ -108,7 +107,10 @@ func init() {
go func() {
for {
<-sig
configure()
err := configure()
if err != nil {
log.Printf("[INIT] [Failed to reload quota files: %v]", err)
}
}
}()
}
Expand Down

0 comments on commit 7f3f77b

Please sign in to comment.