mirror of https://github.com/jetkvm/kvm.git
chore: Enable more linters
Enable more golangci-lint linters. * `forbidigo` to stop use of non-logger console printing. * `goimports` to make sure `import` blocks are formatted nicely. * `misspell` to catch spelling mistakes. * `whitespace` to catch whitespace issues. Signed-off-by: SuperQ <superq@gmail.com>
This commit is contained in:
parent
a9180c972c
commit
aed453cc8c
|
@ -1,12 +1,22 @@
|
||||||
---
|
---
|
||||||
linters:
|
linters:
|
||||||
enable:
|
enable:
|
||||||
# - goimports
|
- forbidigo
|
||||||
# - misspell
|
- goimports
|
||||||
|
- misspell
|
||||||
# - revive
|
# - revive
|
||||||
|
- whitespace
|
||||||
|
|
||||||
issues:
|
issues:
|
||||||
exclude-rules:
|
exclude-rules:
|
||||||
- path: _test.go
|
- path: _test.go
|
||||||
linters:
|
linters:
|
||||||
- errcheck
|
- errcheck
|
||||||
|
|
||||||
|
linters-settings:
|
||||||
|
forbidigo:
|
||||||
|
forbid:
|
||||||
|
- p: ^fmt\.Print.*$
|
||||||
|
msg: Do not commit print statements. Use logger package.
|
||||||
|
- p: ^log\.(Fatal|Panic|Print)(f|ln)?.*$
|
||||||
|
msg: Do not commit log statements. Use logger package.
|
||||||
|
|
|
@ -1,15 +1,11 @@
|
||||||
package kvm
|
package kvm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
versioncollector "github.com/prometheus/client_golang/prometheus/collectors/version"
|
versioncollector "github.com/prometheus/client_golang/prometheus/collectors/version"
|
||||||
"github.com/prometheus/common/version"
|
"github.com/prometheus/common/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
var promHandler http.Handler
|
|
||||||
|
|
||||||
func initPrometheus() {
|
func initPrometheus() {
|
||||||
// A Prometheus metrics endpoint.
|
// A Prometheus metrics endpoint.
|
||||||
version.Version = builtAppVersion
|
version.Version = builtAppVersion
|
||||||
|
|
|
@ -66,7 +66,6 @@ func runATXControl() {
|
||||||
newLedPWRState != ledPWRState ||
|
newLedPWRState != ledPWRState ||
|
||||||
newBtnRSTState != btnRSTState ||
|
newBtnRSTState != btnRSTState ||
|
||||||
newBtnPWRState != btnPWRState {
|
newBtnPWRState != btnPWRState {
|
||||||
|
|
||||||
logger.Debugf("Status changed: HDD LED: %v, PWR LED: %v, RST BTN: %v, PWR BTN: %v",
|
logger.Debugf("Status changed: HDD LED: %v, PWR LED: %v, RST BTN: %v, PWR BTN: %v",
|
||||||
newLedHDDState, newLedPWRState, newBtnRSTState, newBtnPWRState)
|
newLedHDDState, newLedPWRState, newBtnRSTState, newBtnPWRState)
|
||||||
|
|
||||||
|
|
2
web.go
2
web.go
|
@ -16,6 +16,7 @@ import (
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//nolint:typecheck
|
||||||
//go:embed all:static
|
//go:embed all:static
|
||||||
var staticFiles embed.FS
|
var staticFiles embed.FS
|
||||||
|
|
||||||
|
@ -419,7 +420,6 @@ func handleSetup(c *gin.Context) {
|
||||||
|
|
||||||
// Set the cookie
|
// Set the cookie
|
||||||
c.SetCookie("authToken", config.LocalAuthToken, 7*24*60*60, "/", "", false, true)
|
c.SetCookie("authToken", config.LocalAuthToken, 7*24*60*60, "/", "", false, true)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// For noPassword mode, ensure the password field is empty
|
// For noPassword mode, ensure the password field is empty
|
||||||
config.HashedPassword = ""
|
config.HashedPassword = ""
|
||||||
|
|
|
@ -8,10 +8,10 @@ import (
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"crypto/x509/pkix"
|
"crypto/x509/pkix"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"log"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
@ -38,7 +38,7 @@ func RunWebSecureServer() {
|
||||||
TLSConfig: &tls.Config{
|
TLSConfig: &tls.Config{
|
||||||
// TODO: cache certificate in persistent storage
|
// TODO: cache certificate in persistent storage
|
||||||
GetCertificate: func(info *tls.ClientHelloInfo) (*tls.Certificate, error) {
|
GetCertificate: func(info *tls.ClientHelloInfo) (*tls.Certificate, error) {
|
||||||
hostname := WebSecureSelfSignedDefaultDomain
|
var hostname string
|
||||||
if info.ServerName != "" {
|
if info.ServerName != "" {
|
||||||
hostname = info.ServerName
|
hostname = info.ServerName
|
||||||
} else {
|
} else {
|
||||||
|
@ -58,7 +58,6 @@ func RunWebSecureServer() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSelfSignedCert(hostname string) *tls.Certificate {
|
func createSelfSignedCert(hostname string) *tls.Certificate {
|
||||||
|
@ -72,7 +71,8 @@ func createSelfSignedCert(hostname string) *tls.Certificate {
|
||||||
|
|
||||||
priv, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
priv, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to generate private key: %v", err)
|
logger.Errorf("Failed to generate private key: %v", err)
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
keyUsage := x509.KeyUsageDigitalSignature
|
keyUsage := x509.KeyUsageDigitalSignature
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue