소스 검색

feat: add hash and toJson methods

master
Blaz Smehov 1 주 전
부모
커밋
02a72f6853
1개의 변경된 파일25개의 추가작업 그리고 0개의 파일을 삭제
  1. +25
    -0
      internal/pkg/model/typeMethods.go

+ 25
- 0
internal/pkg/model/typeMethods.go 파일 보기

@@ -0,0 +1,25 @@
package model

import (
"crypto/sha256"
"encoding/json"
"fmt"
)

func (b *BeaconEvent) Hash() []byte {
rBatt := (b.Battery / 10) * 10
c := fmt.Sprintf("%d%d%s%s%s", rBatt, b.Event, b.ID, b.Name, b.Type)
h := sha256.New()
h.Write([]byte(c))
bs := h.Sum(nil)

return bs
}

func (b BeaconEvent) ToJSON() ([]byte, error) {
eData, err := json.Marshal(b)
if err != nil {
return nil, err
}
return eData, nil
}

불러오는 중...
취소
저장