Skip to content

Commit

Permalink
docs: add annotations on functions
Browse files Browse the repository at this point in the history
Signed-off-by: kwanhur <[email protected]>
  • Loading branch information
kwanhur committed Mar 18, 2022
1 parent 2487912 commit 3cbe300
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions author.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package main

import "github.com/urfave/cli/v2"

// Authors author list
func Authors() []*cli.Author {
return []*cli.Author{
{
Expand Down
1 change: 1 addition & 0 deletions ipvs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

var mutex sync.Mutex

// IPVS a wrapper of ipvs with its handler
type IPVS struct {
Handler *ipvs.Handle
}
Expand Down
20 changes: 20 additions & 0 deletions operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func (o *Operator) daemon() *ipvs.Daemon {
return &d
}

// Zero clear out all the vs stats
func (o *Operator) Zero() cli.ActionFunc {
return func(c *cli.Context) error {
o.ctx = c
Expand All @@ -158,6 +159,7 @@ func (o *Operator) Zero() cli.ActionFunc {
}
}

// StringService print vs with builtin format
func (o *Operator) StringService() cli.ActionFunc {
return func(c *cli.Context) error {
o.ctx = c
Expand All @@ -173,6 +175,7 @@ func (o *Operator) StringService() cli.ActionFunc {
}
}

// ListService retrieve all the vs then foreach to print
func (o *Operator) ListService() cli.ActionFunc {
return func(c *cli.Context) error {
o.ctx = c
Expand Down Expand Up @@ -205,6 +208,7 @@ func (o *Operator) ListService() cli.ActionFunc {
}
}

// GetService retrieve vs then print it
func (o *Operator) GetService() cli.ActionFunc {
return func(c *cli.Context) error {
o.ctx = c
Expand Down Expand Up @@ -240,6 +244,7 @@ func (o *Operator) GetService() cli.ActionFunc {
}
}

// ExistService check vs existed or not
func (o *Operator) ExistService() cli.ActionFunc {
return func(c *cli.Context) error {
o.ctx = c
Expand All @@ -259,6 +264,7 @@ func (o *Operator) ExistService() cli.ActionFunc {
}
}

// AddService add vs into Linux virtual server table
func (o *Operator) AddService() cli.ActionFunc {
return func(c *cli.Context) error {
o.ctx = c
Expand All @@ -272,6 +278,7 @@ func (o *Operator) AddService() cli.ActionFunc {
}
}

// UpdateService update vs attributes, like scheduler, persistent, timeout, netmask
func (o *Operator) UpdateService() cli.ActionFunc {
return func(c *cli.Context) error {
o.ctx = c
Expand All @@ -285,6 +292,7 @@ func (o *Operator) UpdateService() cli.ActionFunc {
}
}

// DelService delete vs
func (o *Operator) DelService() cli.ActionFunc {
return func(c *cli.Context) error {
o.ctx = c
Expand All @@ -298,6 +306,7 @@ func (o *Operator) DelService() cli.ActionFunc {
}
}

// ZeroService clear out vs' stats
func (o *Operator) ZeroService() cli.ActionFunc {
return func(c *cli.Context) error {
o.ctx = c
Expand All @@ -311,6 +320,7 @@ func (o *Operator) ZeroService() cli.ActionFunc {
}
}

// FlushService clear out all of the Linux virtual table
func (o *Operator) FlushService() cli.ActionFunc {
return func(c *cli.Context) error {
o.ctx = c
Expand All @@ -320,6 +330,7 @@ func (o *Operator) FlushService() cli.ActionFunc {
}
}

// ListServer Retrieve all the servers then foreach to print
func (o *Operator) ListServer() cli.ActionFunc {
return func(c *cli.Context) error {
o.ctx = c
Expand Down Expand Up @@ -368,6 +379,7 @@ func (o *Operator) ListServer() cli.ActionFunc {
}
}

// AddServer add rs into vs
func (o *Operator) AddServer() cli.ActionFunc {
return func(c *cli.Context) error {
o.ctx = c
Expand All @@ -387,6 +399,7 @@ func (o *Operator) AddServer() cli.ActionFunc {
}
}

// DelServer delete rs from vs
func (o *Operator) DelServer() cli.ActionFunc {
return func(c *cli.Context) error {
o.ctx = c
Expand All @@ -406,6 +419,7 @@ func (o *Operator) DelServer() cli.ActionFunc {
}
}

// UpdateServer update rs attributes (weight, forward)
func (o *Operator) UpdateServer() cli.ActionFunc {
return func(c *cli.Context) error {
o.ctx = c
Expand All @@ -425,6 +439,7 @@ func (o *Operator) UpdateServer() cli.ActionFunc {
}
}

// FlushServer clear out all the rs
func (o *Operator) FlushServer() cli.ActionFunc {
return func(c *cli.Context) error {
o.ctx = c
Expand All @@ -448,6 +463,7 @@ func (o *Operator) FlushServer() cli.ActionFunc {
}
}

// ShowDaemon print daemon infos
func (o *Operator) ShowDaemon() cli.ActionFunc {
return func(c *cli.Context) error {
o.ctx = c
Expand All @@ -467,6 +483,7 @@ func (o *Operator) ShowDaemon() cli.ActionFunc {
}
}

// AddDaemon add daemon into Linux virtual server table
func (o *Operator) AddDaemon() cli.ActionFunc {
return func(c *cli.Context) error {
o.ctx = c
Expand All @@ -476,6 +493,7 @@ func (o *Operator) AddDaemon() cli.ActionFunc {
}
}

// DelDaemon delete daemon
func (o *Operator) DelDaemon() cli.ActionFunc {
return func(c *cli.Context) error {
o.ctx = c
Expand All @@ -485,6 +503,7 @@ func (o *Operator) DelDaemon() cli.ActionFunc {
}
}

// ShowTimeout print timeout infos (tcp tcpfin udp)
func (o *Operator) ShowTimeout() cli.ActionFunc {
return func(c *cli.Context) error {
o.ctx = c
Expand All @@ -503,6 +522,7 @@ func (o *Operator) ShowTimeout() cli.ActionFunc {
}
}

// SetTimeout set timeout infos (tcp tcpfin udp)
func (o *Operator) SetTimeout() cli.ActionFunc {
return func(c *cli.Context) error {
o.ctx = c
Expand Down
4 changes: 4 additions & 0 deletions operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ type Operator struct {
ctx *cli.Context
}

// NewOperator operator instance, include all commands (basic, service, server, timeout and daemon)
func NewOperator() *Operator {
return &Operator{}
}

// Commands return supported commands
func (o *Operator) Commands() []*cli.Command {
var cmds []*cli.Command
cmds = append(cmds, o.BasicCommands()...)
Expand All @@ -38,11 +40,13 @@ func (o *Operator) Commands() []*cli.Command {
return cmds
}

// Fatal print error message into STDERR, then exit
func (o *Operator) Fatal(format string, a ...interface{}) {
_, _ = fmt.Fprintf(o.ctx.App.ErrWriter, format, a...)
os.Exit(2)
}

// Print output message into STDOUT
func (o *Operator) Print(format string, a ...interface{}) {
_, _ = fmt.Fprintf(o.ctx.App.Writer, format, a...)
}
8 changes: 7 additions & 1 deletion protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,23 @@
package main

import (
"github.com/kwanhur/ipvs"
"strings"
"syscall"

"github.com/kwanhur/ipvs"
)

// IProtocol protocol wrapper
type IProtocol struct {
proto string
}

// Protocol convert into an IProtocol wrapper
func Protocol(protocol string) IProtocol {
return IProtocol{proto: strings.ToUpper(protocol)}
}

// Code fetch Protocol represents in syscall, non-supported is zero
func (p *IProtocol) Code() uint16 {
switch strings.ToUpper(p.proto) {
case "TCP", "":
Expand All @@ -41,10 +45,12 @@ func (p *IProtocol) Code() uint16 {
}
}

// IPProto convert into IPProto represents ipvs
func (p *IProtocol) IPProto() ipvs.IPProto {
return ipvs.IPProto(p.Code())
}

// Support check it's supported or not
func (p *IProtocol) Support() bool {
switch p.proto {
case "", "TCP", "UDP", "SCTP":
Expand Down

0 comments on commit 3cbe300

Please sign in to comment.