From 7b5d9eba914a8c74d8ed89d39500b687ac5c323e Mon Sep 17 00:00:00 2001 From: flymin <905370712@qq.com> Date: Wed, 25 May 2022 10:19:03 +0800 Subject: [PATCH] name conversion for change request --- README.md | 2 +- config/config.go | 2 +- handle/handle.go | 22 ++++++++++------------ 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 5e1e50e..6b1210f 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ tls-cert: "" tls-key: "" tls-min-vers: "" url-prefix: "" -access_key: "" +access-key: "" ``` Example configuration with possible alternative values: diff --git a/config/config.go b/config/config.go index 216e174..1a01790 100644 --- a/config/config.go +++ b/config/config.go @@ -28,7 +28,7 @@ var ( TLSMinVersStr string `yaml:"tls-min-vers"` URLPrefix string `yaml:"url-prefix"` Referrers []string `yaml:"referrers"` - AccessKey string `yaml:"accessKey"` + AccessKey string `yaml:"access-key"` } ) diff --git a/handle/handle.go b/handle/handle.go index fb59298..7103ba8 100644 --- a/handle/handle.go +++ b/handle/handle.go @@ -159,32 +159,30 @@ func AddCorsWildcardHeaders(serve http.HandlerFunc) http.HandlerFunc { func AddAccessKey(serve http.HandlerFunc, accessKey string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { // Get key or md5sum from this access. - keys, key_ok := r.URL.Query()["key"] + keys, keyOk := r.URL.Query()["key"] var code string - if !key_ok || len(keys[0]) < 1 { + if !keyOk || len(keys[0]) < 1 { // In case a code is provided - codes, code_ok := r.URL.Query()["code"] - if !code_ok || len(codes[0]) < 1 { + codes, codeOk := r.URL.Query()["code"] + if !codeOk || len(codes[0]) < 1 { http.NotFound(w, r) return } - code = codes[0] + code = strings.ToUpper(codes[0]) } else { // In case a key is provided, convert to code. data := []byte(r.URL.Path + keys[0]) hash := md5.Sum(data) - code = fmt.Sprintf("%x", hash) + code = fmt.Sprintf("%X", hash) } - code = strings.ToUpper(code) // Compute the correct md5sum of this access. - local_data := []byte(r.URL.Path + accessKey) - hash := md5.Sum(local_data) - local_code := fmt.Sprintf("%x", hash) - local_code = strings.ToUpper(local_code) + localData := []byte(r.URL.Path + accessKey) + hash := md5.Sum(localData) + localCode := fmt.Sprintf("%X", hash) // Compare the two. - if code != local_code { + if code != localCode { http.NotFound(w, r) return }