Compare commits

15 Commits

3 changed files with 76 additions and 6 deletions

View File

@ -299,8 +299,6 @@ func (sc *AuthCollection) RemoveByAccId(accid primitive.ObjectID) {
sc.lock.Lock()
defer sc.lock.Unlock()
logger.Println("AuthCollection.RemoveByAccId :", accid.Hex())
var sk string
if on, ok := sc.reverseOn[accid]; ok {
sk = on
@ -326,8 +324,6 @@ func (sc *AuthCollection) RemoveBySessionKey(sk string, publish bool) (accid pri
sc.lock.Lock()
defer sc.lock.Unlock()
logger.Println("AuthCollection.RemoveBySessionKey :", sk, publish)
if publish {
// 나한테 있든 없든 무조건 publish해야 함
sc.SessionRemoved(sk)

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에 붙어있다는 뜻
if t := atomic.AddInt64(&healthcheckcounter, 1); t < 0 {
logger.Println("healthCheckHandler return StatusServiceUnavailable :", t)
w.WriteHeader(http.StatusServiceUnavailable)
}
}
@ -127,11 +128,25 @@ func (server *Server) shutdown() {
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)
for atomic.LoadInt64(&healthcheckcounter)-math.MinInt64 > 10 {
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)
timer--
}
logger.Println("http server shutdown. healthcheck completed")
} else {
logger.Println("http server shutdown. no lb")
}
if server.httpserver != nil {