Address a bunch of golint warnings.

This commit is contained in:
Ward Vandewege 2021-04-24 11:26:50 -04:00
parent d30b682a6e
commit f7b6c68d22
7 changed files with 13 additions and 3 deletions

2
api.go
View file

@ -104,7 +104,7 @@ func (h *Headscale) RegistrationHandler(c *gin.Context) {
return return
} }
log.Println("Hey! Not registered. Not asking for key rotation. Send a passive-agressive authurl to register") log.Println("Hey! Not registered. Not asking for key rotation. Send a passive-aggressive authurl to register")
resp.AuthURL = fmt.Sprintf("%s/register?key=%s", resp.AuthURL = fmt.Sprintf("%s/register?key=%s",
h.cfg.ServerURL, mKey.HexString()) h.cfg.ServerURL, mKey.HexString())
respBody, err := encode(resp, &mKey, h.privateKey) respBody, err := encode(resp, &mKey, h.privateKey)

2
app.go
View file

@ -114,10 +114,10 @@ func (h *Headscale) Serve() error {
go func() { go func() {
log.Fatal(http.ListenAndServe(":http", m.HTTPHandler(http.HandlerFunc(h.redirect)))) log.Fatal(http.ListenAndServe(":http", m.HTTPHandler(http.HandlerFunc(h.redirect))))
}() }()
err = s.ListenAndServeTLS("", "")
} else { } else {
return errors.New("Unknown value for TLSLetsEncryptChallengeType") return errors.New("Unknown value for TLSLetsEncryptChallengeType")
} }
err = s.ListenAndServeTLS("", "")
} else if h.cfg.TLSCertPath == "" { } else if h.cfg.TLSCertPath == "" {
if !strings.HasPrefix(h.cfg.ServerURL, "http://") { if !strings.HasPrefix(h.cfg.ServerURL, "http://") {
fmt.Println("WARNING: listening without TLS but ServerURL does not start with http://") fmt.Println("WARNING: listening without TLS but ServerURL does not start with http://")

4
cli.go
View file

@ -51,6 +51,8 @@ func (h *Headscale) RegisterMachine(key string, namespace string) error {
return nil return nil
} }
// ListNodeRoutes prints the subnet routes advertised by a node (identified by
// namespace and node name)
func (h *Headscale) ListNodeRoutes(namespace string, nodeName string) error { func (h *Headscale) ListNodeRoutes(namespace string, nodeName string) error {
m, err := h.GetMachine(namespace, nodeName) m, err := h.GetMachine(namespace, nodeName)
if err != nil { if err != nil {
@ -65,6 +67,8 @@ func (h *Headscale) ListNodeRoutes(namespace string, nodeName string) error {
return nil return nil
} }
// EnableNodeRoute enables a subnet route advertised by a node (identified by
// namespace and node name)
func (h *Headscale) EnableNodeRoute(namespace string, nodeName string, routeStr string) error { func (h *Headscale) EnableNodeRoute(namespace string, nodeName string, routeStr string) error {
m, err := h.GetMachine(namespace, nodeName) m, err := h.GetMachine(namespace, nodeName)
if err != nil { if err != nil {

2
db.go
View file

@ -4,7 +4,7 @@ import (
"errors" "errors"
"github.com/jinzhu/gorm" "github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/postgres" _ "github.com/jinzhu/gorm/dialects/postgres" // sql driver
) )
const dbVersion = "1" const dbVersion = "1"

View file

@ -176,6 +176,7 @@ func (h *Headscale) getPeers(m Machine) (*[]*tailcfg.Node, error) {
return &peers, nil return &peers, nil
} }
// GetMachine finds a Machine by name and namespace and returns the Machine struct
func (h *Headscale) GetMachine(namespace string, name string) (*Machine, error) { func (h *Headscale) GetMachine(namespace string, name string) (*Machine, error) {
machines, err := h.ListMachinesInNamespace(namespace) machines, err := h.ListMachinesInNamespace(namespace)
if err != nil { if err != nil {
@ -190,6 +191,7 @@ func (h *Headscale) GetMachine(namespace string, name string) (*Machine, error)
return nil, fmt.Errorf("not found") return nil, fmt.Errorf("not found")
} }
// GetHostInfo returns a Hostinfo struct for the machine
func (m *Machine) GetHostInfo() (*tailcfg.Hostinfo, error) { func (m *Machine) GetHostInfo() (*tailcfg.Hostinfo, error) {
hostinfo := tailcfg.Hostinfo{} hostinfo := tailcfg.Hostinfo{}
if len(m.HostInfo.RawMessage) != 0 { if len(m.HostInfo.RawMessage) != 0 {

View file

@ -91,6 +91,7 @@ func (h *Headscale) ListMachinesInNamespace(name string) (*[]Machine, error) {
return &machines, nil return &machines, nil
} }
// SetMachineNamespace assigns a Machine to a namespace
func (h *Headscale) SetMachineNamespace(m *Machine, namespaceName string) error { func (h *Headscale) SetMachineNamespace(m *Machine, namespaceName string) error {
n, err := h.GetNamespace(namespaceName) n, err := h.GetNamespace(namespaceName)
if err != nil { if err != nil {

View file

@ -7,6 +7,7 @@ import (
"time" "time"
) )
// PreAuthKey describes a pre-authorization key usable in a particular namespace
type PreAuthKey struct { type PreAuthKey struct {
ID uint64 `gorm:"primary_key"` ID uint64 `gorm:"primary_key"`
Key string Key string
@ -18,6 +19,7 @@ type PreAuthKey struct {
Expiration *time.Time Expiration *time.Time
} }
// CreatePreAuthKey creates a new PreAuthKey in a namespace, and returns it
func (h *Headscale) CreatePreAuthKey(namespaceName string, reusable bool, expiration *time.Time) (*PreAuthKey, error) { func (h *Headscale) CreatePreAuthKey(namespaceName string, reusable bool, expiration *time.Time) (*PreAuthKey, error) {
n, err := h.GetNamespace(namespaceName) n, err := h.GetNamespace(namespaceName)
if err != nil { if err != nil {
@ -49,6 +51,7 @@ func (h *Headscale) CreatePreAuthKey(namespaceName string, reusable bool, expira
return &k, nil return &k, nil
} }
// GetPreAuthKeys returns the list of PreAuthKeys for a namespace
func (h *Headscale) GetPreAuthKeys(namespaceName string) (*[]PreAuthKey, error) { func (h *Headscale) GetPreAuthKeys(namespaceName string) (*[]PreAuthKey, error) {
n, err := h.GetNamespace(namespaceName) n, err := h.GetNamespace(namespaceName)
if err != nil { if err != nil {