Skip to content

Commit a3bbf37

Browse files
committed
keyを指定できるように変更
1 parent 4217acd commit a3bbf37

File tree

2 files changed

+4
-25
lines changed

2 files changed

+4
-25
lines changed

example/main.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,8 @@ func rootHandler(w http.ResponseWriter, r *http.Request) {
1313

1414
func createHandler(w http.ResponseWriter, r *http.Request) {
1515
ip := r.RemoteAddr
16-
result, err := memory_retention.CreateKey(ip)
17-
if err != nil {
18-
fmt.Fprintln(w, err)
19-
return
20-
}
21-
fmt.Fprintln(w, result)
16+
memory_retention.CreateKey(ip)
17+
fmt.Fprintln(w, ip)
2218
}
2319

2420
func addHandler(w http.ResponseWriter, r *http.Request) {

memory_retention.go

+2-19
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
package memory_retention
22

33
import (
4-
"crypto/sha256"
5-
"encoding/hex"
64
"fmt"
7-
"strings"
85
"sync"
9-
"time"
106
)
117

128
var mutex = &sync.Mutex{}
@@ -22,24 +18,11 @@ var keyMap = make(map[string]bool)
2218
// Create a key.
2319
//
2420
// Arguments:
25-
// seed {string} - Seed value for generating the key.
26-
//
27-
// Returns:
28-
// {string} - The generated hash value. Use this value to add/remove values.
29-
func CreateKey(seed string) (string, error) {
30-
var strBuild strings.Builder
31-
32-
strBuild.WriteString(seed)
33-
strBuild.WriteString(time.Now().String())
34-
35-
result := sha256.Sum256([]byte(strBuild.String()))
36-
hash := hex.EncodeToString(result[:])
37-
21+
// hash {string} - hash value.
22+
func CreateKey(hash string) {
3823
mutex.Lock()
3924
keyMap[hash] = true
4025
mutex.Unlock()
41-
42-
return hash, nil
4326
}
4427

4528
// Deletes the specified key.

0 commit comments

Comments
 (0)