Compare commits

11 Commits

Author SHA1 Message Date
c31f838ba8 쿠폰 이름 해시 로직 변경 2024-02-05 15:08:41 +09:00
f9a146321c 최대 1분 후에 종료 2023-09-12 16:59:17 +09:00
ea8ae4d02c 쿠폰 헬퍼 함수 추가 2023-09-12 16:48:42 +09:00
8173216e95 Merge branch 'master' into kd-live 2023-07-10 17:58:10 +09:00
f4510f8990 버그 수정;;;;;바본가;; 2023-07-10 17:58:00 +09:00
ead6543d95 Merge branch 'master' into kd-live 2023-07-10 17:53:35 +09:00
38683eb616 healthcheck 수정 2023-07-10 17:53:23 +09:00
dd05ebf6ce Merge branch 'master' into kd-live 2023-07-10 17:46:25 +09:00
b759f13eee healthcheck 수정 2023-07-10 17:46:05 +09:00
3024a17b54 Merge branch 'master' into kd-live 2023-07-10 17:16:12 +09:00
a9de99b04a healthCheckHandler 로그 추가 2023-07-10 17:15:59 +09:00
2 changed files with 76 additions and 2 deletions

59
coupon/helper.go Normal file
View File

@ -0,0 +1,59 @@
package coupon
import (
"crypto/md5"
"encoding/binary"
"encoding/hex"
"math/rand"
"strings"
)
func DisolveCouponCode(code string) (round string, key string) {
var final []byte
for _, n := range strings.Split(code, "-") {
nb, err := hex.DecodeString(n)
if err != nil {
// 형식 오류
return "", ""
}
final = append(final, nb...)
}
if len(final) != 8 {
// 형식 오류
return "", ""
}
uid := final[4:]
left := binary.BigEndian.Uint16(uid[0:2])
right := binary.BigEndian.Uint16(uid[2:4])
final = final[0:4]
xor := binary.LittleEndian.Uint32(final)
roundhashnum := xor ^ (uint32(left) * uint32(right))
roundhash := make([]byte, 4)
binary.BigEndian.PutUint32(roundhash, roundhashnum)
round = hex.EncodeToString(roundhash)
key = hex.EncodeToString(uid)
return
}
func MakeCouponRoundHash(name string) (hash string, roundNumber uint32) {
m5 := md5.New()
m5.Write([]byte(name))
hashbt := m5.Sum(nil)
roundbt := make([]byte, 8)
copy(roundbt, hashbt[:8])
roundseed := int64(binary.BigEndian.Uint64(roundbt))
roundhash := make([]byte, 4)
rand.New(rand.NewSource(roundseed)).Read(roundhash)
roundNumber = binary.BigEndian.Uint32(roundhash)
hash = hex.EncodeToString(roundhash)
return
}

View File

@ -73,6 +73,7 @@ func healthCheckHandler(w http.ResponseWriter, r *http.Request) {
// 한번이라도 들어오면 lb에 붙어있다는 뜻 // 한번이라도 들어오면 lb에 붙어있다는 뜻
if t := atomic.AddInt64(&healthcheckcounter, 1); t < 0 { if t := atomic.AddInt64(&healthcheckcounter, 1); t < 0 {
logger.Println("healthCheckHandler return StatusServiceUnavailable :", t)
w.WriteHeader(http.StatusServiceUnavailable) w.WriteHeader(http.StatusServiceUnavailable)
} }
} }
@ -127,11 +128,25 @@ func (server *Server) shutdown() {
signal.Stop(server.interrupt) signal.Stop(server.interrupt)
if atomic.LoadInt64(&healthcheckcounter) > 0 { if t := atomic.LoadInt64(&healthcheckcounter); t > 0 {
logger.Println("http server shutdown. healthcheckcounter :", t)
atomic.StoreInt64(&healthcheckcounter, math.MinInt64) atomic.StoreInt64(&healthcheckcounter, math.MinInt64)
for atomic.LoadInt64(&healthcheckcounter)-math.MinInt64 == 0 {
timer := 600 // 0.1 * 600 = 1분
for cnt := 0; cnt < 100 && timer > 0; {
next := atomic.LoadInt64(&healthcheckcounter)
if next == t {
cnt++
} else {
t = next
cnt = 0
}
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
timer--
} }
logger.Println("http server shutdown. healthcheck completed")
} else {
logger.Println("http server shutdown. no lb")
} }
if server.httpserver != nil { if server.httpserver != nil {