원하는 패키지 매니저로 프로젝트에 SDK를 추가하세요.
npm install net/httpyarn add net/httppnpm add net/http최소한의 설정으로 시작하고 실행하세요.
package mainimport ( "fmt" "io" "net/http")func main() { http.HandleFunc("/webhook/tracio", func(w http.ResponseWriter, r *http.Request) { body, _ := io.ReadAll(r.Body) // verify r.Header.Get("X-Tracio-Signature") against body, then act fmt.Println(string(body)) w.WriteHeader(http.StatusOK) }) http.ListenAndServe(":8080", nil)}오류 처리, 로딩 상태, 고급 구성을 갖춘 프로덕션 준비 패턴.
package mainimport ( "crypto/hmac" "crypto/sha256" "encoding/hex" "encoding/json" "io" "log" "net/http" "os" "strings")type Event struct { VisitorID string `json:"visitorId"` Bot struct { Result string `json:"result"` } `json:"bot"` Decision struct { RiskScore int `json:"riskScore"` } `json:"decision"`}// verify recomputes the HMAC-SHA256 over "<t>.<rawBody>" and compares it.func verify(body []byte, header, secret string) bool { parts := map[string]string{} for _, kv := range strings.Split(header, ",") { if p := strings.SplitN(kv, "=", 2); len(p) == 2 { parts[p[0]] = p[1] } } mac := hmac.New(sha256.New, []byte(secret)) mac.Write([]byte(parts["t"] + ".")) mac.Write(body) expected := hex.EncodeToString(mac.Sum(nil)) return hmac.Equal([]byte(expected), []byte(parts["v1"]))}func main() { secret := os.Getenv("TRACIO_WEBHOOK_SECRET") http.HandleFunc("/webhook/tracio", func(w http.ResponseWriter, r *http.Request) { body, _ := io.ReadAll(r.Body) if !verify(body, r.Header.Get("X-Tracio-Signature"), secret) { http.Error(w, "Invalid signature", http.StatusUnauthorized) return } var e Event if err := json.Unmarshal(body, &e); err != nil { http.Error(w, "Bad payload", http.StatusBadRequest) return } if e.Bot.Result == "bot" || e.Decision.RiskScore > 50 { log.Printf("flagging visitor %s (bot=%s risk=%d)", e.VisitorID, e.Bot.Result, e.Decision.RiskScore) } w.WriteHeader(http.StatusOK) }) log.Fatal(http.ListenAndServe(":8080", nil))}SDK를 초기화하고 구성하기 위한 모든 옵션.
publicKeystring대시보드에서 발급받은 공개 키 — 브라우저에 실어 보내도 안전합니다endpointstring프록시 라우팅 배포를 위한 사용자 지정 엔드포인트 URL — 명시적 URL이 region보다 우선합니다regionstring데이터 리전: us 또는 eutimeoutMsnumbergetResult() 호출 전체에 대한 타임아웃(밀리초)linkedIdstring로그인한 사용자의 내부 계정 ID — 같은 디바이스를 공유하는 방문을 연결할 수 있습니다tagstring식별 요청에 붙이는 자유 형식 라벨 (예: checkout 또는 login)debugboolean스크립트 수명 주기와 네트워크 활동을 브라우저 콘솔에 기록합니다scriptUrlstring에이전트 스크립트 URL 전체 재정의 — 셀프 호스팅 또는 Subresource Integrity용전체 API 레퍼런스, 웹훅 구성, 고급 가이드로 더 깊이 알아보세요.