implemented problem route
This commit is contained in:
parent
8a17bd966f
commit
8ae92884dd
22
handlers.go
22
handlers.go
@ -8,21 +8,37 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type prob struct {
|
||||
Operation string
|
||||
First int
|
||||
Last int
|
||||
}
|
||||
|
||||
func attempt(w http.ResponseWriter, req *http.Request) {
|
||||
operation := "+"
|
||||
if r := rand.Intn(2); r == 0 {
|
||||
operation = "-"
|
||||
}
|
||||
|
||||
r := map[string]string{
|
||||
"operation": operation,
|
||||
first := rand.Intn(MAX)
|
||||
var second int
|
||||
if operation == "-" {
|
||||
if first == 0 {
|
||||
second = 0
|
||||
} else {
|
||||
second = rand.Intn(first)
|
||||
}
|
||||
} else {
|
||||
second = rand.Intn(MAX)
|
||||
}
|
||||
|
||||
r := prob{operation, first, second}
|
||||
|
||||
b, err := json.Marshal(r)
|
||||
if err != nil {
|
||||
log.Fatal("issue with json marshalling")
|
||||
}
|
||||
j := string(b)
|
||||
j := string(b)
|
||||
fmt.Println(j)
|
||||
fmt.Fprintf(w, j)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user