Skip to content

Commit

Permalink
Update frequency
Browse files Browse the repository at this point in the history
  • Loading branch information
troydai committed Nov 28, 2024
1 parent 08ca683 commit ffcb17e
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package main

import (
"net/http"
"os"
"strconv"
"sync/atomic"
)

func (s *server) handler(w http.ResponseWriter, r *http.Request) {
if newValue := s.counter.Add(1); newValue%s.frequency == 0 {
panic("crash after 10 requests")
}

w.WriteHeader(200)
}

type server struct {
counter *atomic.Uint64
frequency uint64
}

func main() {
ev := os.Getenv("HTTP_CRASH_FREQUENCY")
frequency, err := strconv.ParseUint(ev, 10, 64)
if err != nil {
frequency = 10
}

s := &server{
counter: &atomic.Uint64{},
frequency: frequency,
}

http.HandleFunc("/", s.handler)
http.ListenAndServe(":8080", nil)
}

0 comments on commit ffcb17e

Please sign in to comment.