mirror of https://github.com/jetkvm/kvm.git
Fixup various linter issues.
Signed-off-by: SuperQ <superq@gmail.com>
This commit is contained in:
parent
6a06788050
commit
adfe055367
|
@ -33,16 +33,17 @@ func (r remoteImageBackend) ReadAt(p []byte, off int64) (n int, err error) {
|
|||
readLen = mountedImageSize - off
|
||||
}
|
||||
var data []byte
|
||||
if source == WebRTC {
|
||||
switch source {
|
||||
case WebRTC:
|
||||
data, err = webRTCDiskReader.Read(ctx, off, readLen)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
n = copy(p, data)
|
||||
return n, nil
|
||||
} else if source == HTTP {
|
||||
case HTTP:
|
||||
return httpRangeReader.ReadAt(p, off)
|
||||
} else {
|
||||
default:
|
||||
return 0, errors.New("unknown image source")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -221,7 +221,7 @@ func startBacklightTickers() {
|
|||
defer dimTicker.Stop()
|
||||
|
||||
go func() {
|
||||
for { //nolint:gosimple
|
||||
for { //nolint:staticcheck
|
||||
select {
|
||||
case <-dimTicker.C:
|
||||
tick_displayDim()
|
||||
|
@ -236,7 +236,7 @@ func startBacklightTickers() {
|
|||
defer offTicker.Stop()
|
||||
|
||||
go func() {
|
||||
for { //nolint:gosimple
|
||||
for { //nolint:staticcheck
|
||||
select {
|
||||
case <-offTicker.C:
|
||||
tick_displayOff()
|
||||
|
|
2
fuse.go
2
fuse.go
|
@ -37,7 +37,7 @@ func (f *WebRTCStreamFile) Getattr(ctx context.Context, fh fs.FileHandle, out *f
|
|||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
out.Attr = f.Attr
|
||||
out.Attr.Size = f.size
|
||||
out.Size = f.size
|
||||
return fs.OK
|
||||
}
|
||||
|
||||
|
|
|
@ -49,12 +49,12 @@ func (s *CertStore) ensureStorePath() error {
|
|||
s.log.Trace().Str("path", s.storePath).Msg("TLS store directory does not exist, creating directory")
|
||||
err = os.MkdirAll(s.storePath, 0755)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to create TLS store path: %w", err)
|
||||
return fmt.Errorf("failed to create TLS store path: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("Failed to check TLS store path: %w", err)
|
||||
return fmt.Errorf("failed to check TLS store path: %w", err)
|
||||
}
|
||||
|
||||
func (s *CertStore) LoadCertificates() {
|
||||
|
@ -115,7 +115,7 @@ func (s *CertStore) GetCertificate(hostname string) *tls.Certificate {
|
|||
func (s *CertStore) ValidateAndSaveCertificate(hostname string, cert string, key string, ignoreWarning bool) (error, error) {
|
||||
tlsCert, err := tls.X509KeyPair([]byte(cert), []byte(key))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to parse certificate: %w", err), nil
|
||||
return fmt.Errorf("failed to parse certificate: %w", err), nil
|
||||
}
|
||||
|
||||
// this can be skipped as current implementation supports one custom certificate only
|
||||
|
@ -129,7 +129,7 @@ func (s *CertStore) ValidateAndSaveCertificate(hostname string, cert string, key
|
|||
|
||||
if err = tlsCert.Leaf.VerifyHostname(hostname); err != nil {
|
||||
if !ignoreWarning {
|
||||
return nil, fmt.Errorf("Certificate does not match hostname: %w", err)
|
||||
return nil, fmt.Errorf("certificate does not match hostname: %w", err)
|
||||
}
|
||||
s.log.Warn().Err(err).Msg("Certificate does not match hostname")
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ func keyToFile(cert *tls.Certificate, filename string) error {
|
|||
case *ecdsa.PrivateKey:
|
||||
b, e := x509.MarshalECPrivateKey(k)
|
||||
if e != nil {
|
||||
return fmt.Errorf("Failed to marshal EC private key: %v", e)
|
||||
return fmt.Errorf("failed to marshal EC private key: %v", e)
|
||||
}
|
||||
|
||||
keyBlock = pem.Block{
|
||||
|
@ -43,7 +43,7 @@ func keyToFile(cert *tls.Certificate, filename string) error {
|
|||
Bytes: b,
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("Unknown private key type: %T", k)
|
||||
return fmt.Errorf("unknown private key type: %T", k)
|
||||
}
|
||||
|
||||
err := withSecretFile(filename, func(file *os.File) error {
|
||||
|
@ -51,7 +51,7 @@ func keyToFile(cert *tls.Certificate, filename string) error {
|
|||
})
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to save private key: %w", err)
|
||||
return fmt.Errorf("failed to save private key: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -67,7 +67,7 @@ func certToFile(cert *tls.Certificate, filename string) error {
|
|||
|
||||
err := pem.Encode(file, &block)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to save certificate: %w", err)
|
||||
return fmt.Errorf("failed to save certificate: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
10
jsonrpc.go
10
jsonrpc.go
|
@ -638,18 +638,20 @@ func rpcSetActiveExtension(extensionId string) error {
|
|||
if config.ActiveExtension == extensionId {
|
||||
return nil
|
||||
}
|
||||
if config.ActiveExtension == "atx-power" {
|
||||
switch config.ActiveExtension {
|
||||
case "atx-power":
|
||||
_ = unmountATXControl()
|
||||
} else if config.ActiveExtension == "dc-power" {
|
||||
case "dc-power":
|
||||
_ = unmountDCControl()
|
||||
}
|
||||
config.ActiveExtension = extensionId
|
||||
if err := SaveConfig(); err != nil {
|
||||
return fmt.Errorf("failed to save config: %w", err)
|
||||
}
|
||||
if extensionId == "atx-power" {
|
||||
switch extensionId {
|
||||
case "atx-power":
|
||||
_ = mountATXControl()
|
||||
} else if extensionId == "dc-power" {
|
||||
case "dc-power":
|
||||
_ = mountDCControl()
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -211,9 +211,10 @@ var defaultMode = &serial.Mode{
|
|||
|
||||
func initSerialPort() {
|
||||
_ = reopenSerialPort()
|
||||
if config.ActiveExtension == "atx-power" {
|
||||
switch config.ActiveExtension {
|
||||
case "atx-power":
|
||||
_ = mountATXControl()
|
||||
} else if config.ActiveExtension == "dc-power" {
|
||||
case "dc-power":
|
||||
_ = mountDCControl()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,11 +62,11 @@ func onDiskMessage(msg webrtc.DataChannelMessage) {
|
|||
func mountImage(imagePath string) error {
|
||||
err := setMassStorageImage("")
|
||||
if err != nil {
|
||||
return fmt.Errorf("Remove Mass Storage Image Error: %w", err)
|
||||
return fmt.Errorf("remove Mass Storage Image Error: %w", err)
|
||||
}
|
||||
err = setMassStorageImage(imagePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Set Mass Storage Image Error: %w", err)
|
||||
return fmt.Errorf("set Mass Storage Image Error: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -476,10 +476,8 @@ func handleUploadChannel(d *webrtc.DataChannel) {
|
|||
}
|
||||
totalBytesWritten += int64(bytesWritten)
|
||||
|
||||
sendProgress := false
|
||||
if time.Since(lastProgressTime) >= 200*time.Millisecond {
|
||||
sendProgress = true
|
||||
}
|
||||
sendProgress := time.Since(lastProgressTime) >= 200*time.Millisecond
|
||||
|
||||
if totalBytesWritten >= pendingUpload.Size {
|
||||
sendProgress = true
|
||||
close(uploadComplete)
|
||||
|
|
11
web_tls.go
11
web_tls.go
|
@ -52,12 +52,13 @@ func initCertStore() {
|
|||
}
|
||||
|
||||
func getCertificate(info *tls.ClientHelloInfo) (*tls.Certificate, error) {
|
||||
if config.TLSMode == "self-signed" {
|
||||
switch config.TLSMode {
|
||||
case "self-signed":
|
||||
if isTimeSyncNeeded() || !timeSyncSuccess {
|
||||
return nil, fmt.Errorf("time is not synced")
|
||||
}
|
||||
return certSigner.GetCertificate(info)
|
||||
} else if config.TLSMode == "custom" {
|
||||
case "custom":
|
||||
return certStore.GetCertificate(webSecureCustomCertificateName), nil
|
||||
}
|
||||
|
||||
|
@ -110,7 +111,7 @@ func setTLSState(s TLSState) error {
|
|||
err, _ := certStore.ValidateAndSaveCertificate(webSecureCustomCertificateName, s.Certificate, s.PrivateKey, true)
|
||||
// warn doesn't matter as ... we don't know the hostname yet
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to save certificate: %w", err)
|
||||
return fmt.Errorf("failed to save certificate: %w", err)
|
||||
}
|
||||
config.TLSMode = "custom"
|
||||
case "self-signed":
|
||||
|
@ -169,7 +170,7 @@ func runWebSecureServer() {
|
|||
websecureLogger.Info().Str("listen", webSecureListen).Msg("Starting websecure server")
|
||||
|
||||
go func() {
|
||||
for _ = range stopTLS {
|
||||
for range stopTLS {
|
||||
websecureLogger.Info().Msg("Shutting down websecure server")
|
||||
err := server.Shutdown(context.Background())
|
||||
if err != nil {
|
||||
|
@ -201,7 +202,7 @@ func startWebSecureServer() {
|
|||
}
|
||||
|
||||
func RunWebSecureServer() {
|
||||
for _ = range startTLS {
|
||||
for range startTLS {
|
||||
websecureLogger.Info().Msg("Starting websecure server, as we have received a start signal")
|
||||
if certStore == nil {
|
||||
initCertStore()
|
||||
|
|
Loading…
Reference in New Issue