small pixel drawing of a pufferfish cascade

sharpen some things up
Jes Olson j3s@c3f.net
Wed, 01 Mar 2023 19:34:12 -0800
commit

893b135677a44f3dfb2f8e76986df430f3e5d5af

parent

a560dfbf0825c14addf08b4641364e8a2b550737

M agent/agent.goagent/agent.go

@@ -169,7 +169,7 @@ return nil

} func (a *Agent) serveAPI(handler http.Handler) { - portStr := fmt.Sprintf(":%d", a.Config.HTTPBindAddr.Port) + portStr := fmt.Sprintf("%s:%d", a.Config.HTTPBindAddr.IP.String(), a.Config.HTTPBindAddr.Port) if err := http.ListenAndServe(portStr, handler); err != nil { a.logger.Error("api error", err) }
M api/agent.goapi/agent.go

@@ -7,13 +7,12 @@ Addr string

Port uint16 Tags map[string]string // Status of the Member which corresponds to github.com/hashicorp/serf/serf.MemberStatus - // Value is one of: // - // AgentMemberNone = 0 - // AgentMemberAlive = 1 - // AgentMemberLeaving = 2 - // AgentMemberLeft = 3 - // AgentMemberFailed = 4 + // AgentMemberNone = 0 + // AgentMemberAlive = 1 + // AgentMemberLeaving = 2 + // AgentMemberLeft = 3 + // AgentMemberFailed = 4 Status int ProtocolMin uint8 ProtocolMax uint8

@@ -24,7 +23,7 @@ DelegateCur uint8

} func (am *AgentMember) StatusPretty() string { - result := "unknown" + var result string switch am.Status { case 0: result = "none"

@@ -36,13 +35,15 @@ case 3:

result = "left" case 4: result = "failed" + default: + result = "unknown" } return result } // XXX: this may be needed for consul compatability, but I'm leaving it // out for now in case it isn't. -const AllSegments = "_all" +// const AllSegments = "_all" // Agent can be used to query the Agent endpoints type Agent struct {
M api/api.goapi/api.go

@@ -69,7 +69,7 @@

return config } -// Client provides a client to the Consul API +// Client provides a client to the cascade API type Client struct { modifyLock sync.RWMutex headers http.Header

@@ -95,22 +95,6 @@ }

} return ret -} - -// AddHeader allows a single header key/value pair to be added -// in a race-safe fashion. -func (c *Client) AddHeader(key, value string) { - c.modifyLock.Lock() - defer c.modifyLock.Unlock() - c.headers.Add(key, value) -} - -// SetHeaders clears all previous headers and uses only the given -// ones going forward. -func (c *Client) SetHeaders(headers http.Header) { - c.modifyLock.Lock() - defer c.modifyLock.Unlock() - c.headers = headers } // NewClient returns a new client

@@ -434,20 +418,3 @@ io.Copy(&buf, resp.Body)

closeResponseBody(resp) return fmt.Errorf("Unexpected response code: %d (%s)", resp.StatusCode, buf.Bytes()) } - -func requireNotFoundOrOK(d time.Duration, resp *http.Response, e error) (bool, time.Duration, *http.Response, error) { - if e != nil { - if resp != nil { - closeResponseBody(resp) - } - return false, d, nil, e - } - switch resp.StatusCode { - case 200: - return true, d, resp, nil - case 404: - return false, d, resp, nil - default: - return false, d, nil, generateUnexpectedResponseCodeError(resp) - } -}
M command/list/list.gocommand/ls/ls.go

@@ -1,14 +1,14 @@

-package list +package ls import ( "fmt" "os" - "git.j3s.sh/cascade/command/list/members" + "git.j3s.sh/cascade/command/ls/members" ) -const usage = `cascade ls nodes -cascade ls members +const usage = `cascade ls members +cascade ls nodes cascade ls services `
M command/list/members/members.gocommand/ls/members/members.go

@@ -46,12 +46,9 @@ }

members, err := client.Agent().Members() for _, m := range members { if membersFlags.details { - fmt.Printf("%s ", m.Name) - fmt.Printf("%s:%d ", m.Addr, m.Port) - fmt.Printf("%s", m.StatusPretty()) - fmt.Printf("\n") + fmt.Printf("%s %s:%d %s\n", m.Name, m.Addr, m.Port, m.StatusPretty()) } else { - fmt.Printf("%s\n", m.Name) + fmt.Println(m.Name) } } }
M command/list/nodes/nodes.gocommand/ls/services/services.go

@@ -1,4 +1,4 @@

-package list +package services import ( "fmt"
M command/list/services/services.gocommand/ls/nodes/nodes.go

@@ -1,4 +1,4 @@

-package list +package nodes import ( "fmt"
M main.gomain.go

@@ -5,7 +5,7 @@ "fmt"

"os" "git.j3s.sh/cascade/command/agent" - "git.j3s.sh/cascade/command/list" + "git.j3s.sh/cascade/command/ls" ) const usage = `cascade agent start a cascade agent

@@ -25,8 +25,8 @@ args := os.Args[2:]

switch os.Args[1] { case "agent": agent.Run(args) - case "list", "ls": - list.Run(args) + case "ls": + ls.Run(args) default: fmt.Fprintf(os.Stderr, "'%s' is not a valid command\n\n%s", command, usage) os.Exit(1)