/
kafkaAvroHandlers.go
35 lines (30 loc) · 1.03 KB
/
kafkaAvroHandlers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package handlers
import (
"net/http"
"github.com/jonsteck/myAvro"
"github.com/jonsteck/kafka"
)
//wrap handler functions to make required handler format: func(http.ResponseWriter, *http.Request)
func MakeHandler(fn func(http.ResponseWriter, *http.Request, *kafka.Server), s *kafka.Server) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
fn(w, r, s)
}
}
//ad handler - calls avro to encode value
func AdHandlerKafkaAvro(w http.ResponseWriter, r *http.Request, s *kafka.Server) {
topic := "ad"
value := myAvro.MyEncode(r.URL.Path[4:])
s.KafkaSendAvro(w, topic, value)
}
//click handler - calls avro to encode value
func ClickHandlerKafkaAvro(w http.ResponseWriter, r *http.Request, s *kafka.Server) {
topic := "click"
value := myAvro.MyEncode(r.URL.Path[7:])
s.KafkaSendAvro(w, topic, value)
}
//win handler - calls avro to encode value
func WinHandlerKafkaAvro(w http.ResponseWriter, r *http.Request, s *kafka.Server) {
topic := "win"
value := myAvro.MyEncode(r.URL.Path[5:])
s.KafkaSendAvro(w, topic, value)
}