mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2025-10-31 01:58:11 +08:00
fatal error: sync: unlock of unlocked mutex goroutine 6 [running]: runtime.throw(0x1420562, 0x1e) /usr/local/go/src/runtime/panic.go:1117 +0x72 fp=0xc0000b5ec8 sp=0xc0000b5e98 pc=0x439e92 sync.throw(0x1420562, 0x1e) /usr/local/go/src/runtime/panic.go:1103 +0x35 fp=0xc0000b5ee8 sp=0xc0000b5ec8 pc=0x46e395 sync.(*Mutex).unlockSlow(0x1f97138, 0xffffffff) /usr/local/go/src/sync/mutex.go:196 +0xd8 fp=0xc0000b5f10 sp=0xc0000b5ee8 pc=0x47d458 sync.(*Mutex).Unlock(...) /usr/local/go/src/sync/mutex.go:190 github.com/mickael-kerjean/filestash/server/common.(*Configuration).Get(0x1f97120, 0x140a506, 0x14, 0x0) /home/mickael/Documents/projects/filestash/server/common/config.go:438 +0x113 fp=0xc0000b5f90 sp=0xc0000b5f10 pc=0x7ba313 github.com/mickael-kerjean/filestash/server/common.init.0.func1(0x0) /home/mickael/Documents/projects/filestash/server/common/api.go:16 +0x46 fp=0xc0000b5fc0 sp=0xc0000b5f90 pc=0x7c7906 github.com/mickael-kerjean/filestash/server/common.init.0.func3() /home/mickael/Documents/projects/filestash/server/common/api.go:40 +0x29 fp=0xc0000b5fe0 sp=0xc0000b5fc0 pc=0x7c7c49 runtime.goexit() /usr/local/go/src/runtime/asm_amd64.s:1371 +0x1 fp=0xc0000b5fe8 sp=0xc0000b5fe0 pc=0x4733e1 created by github.com/mickael-kerjean/filestash/server/common.init.0 /home/mickael/Documents/projects/filestash/server/common/api.go:39 +0x5a goroutine 1 [runnable, locked to thread]: os.(*File).Read(0xc000186000, 0xc000280400, 0x100, 0x100, 0x401, 0xc000280000, 0x400) /usr/local/go/src/os/file.go:113 +0x265 io.ReadAll(0x1677e40, 0xc000186000, 0x0, 0x1ff, 0xc000186000, 0x0, 0x0) /usr/local/go/src/io/io.go:633 +0xdf io/ioutil.ReadAll(...) /usr/local/go/src/io/ioutil/ioutil.go:27 github.com/mickael-kerjean/filestash/server/common.LoadConfig(0x0, 0x0, 0x0, 0x1fc66e0, 0x0) /home/mickael/Documents/projects/filestash/server/common/config_state.go:32 +0x85 github.com/mickael-kerjean/filestash/server/common.(*Configuration).Load(0x1f97120) /home/mickael/Documents/projects/filestash/server/common/config.go:214 +0x34 github.com/mickael-kerjean/filestash/server/common.init.1() /home/mickael/Documents/projects/filestash/server/common/config.go:53 +0x85
38 lines
835 B
Go
38 lines
835 B
Go
package common
|
|
|
|
import (
|
|
"os"
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
func VerifyApiKey(api_key string) (host string, err error) {
|
|
isApiEnabled := Config.Get("features.api.enable").Bool()
|
|
apiKey := Config.Get("feature.api.api_key").String()
|
|
|
|
if isApiEnabled == false {
|
|
return "", NewError("Api is not enabled", 503)
|
|
} else if apiKey == os.Getenv("API_KEY") {
|
|
return "*", nil
|
|
}
|
|
lines := strings.Split(apiKey, "\n")
|
|
for _, line := range lines {
|
|
line = regexp.MustCompile(` #.*`).ReplaceAllString(line, "") // remove comment
|
|
chunks := strings.SplitN(line, " ", 2)
|
|
if len(chunks) == 0 {
|
|
continue
|
|
} else if chunks[0] != apiKey {
|
|
continue
|
|
}
|
|
if len(chunks) == 1 {
|
|
return "", nil
|
|
}
|
|
chunks[1] = strings.TrimSpace(chunks[1])
|
|
if chunks[1] == "" {
|
|
return "*", nil
|
|
}
|
|
return chunks[1], nil
|
|
}
|
|
return "", ErrNotValid
|
|
}
|