implemented problem route
This commit is contained in:
parent
8a17bd966f
commit
8ae92884dd
20
handlers.go
20
handlers.go
@ -8,15 +8,31 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type prob struct {
|
||||||
|
Operation string
|
||||||
|
First int
|
||||||
|
Last int
|
||||||
|
}
|
||||||
|
|
||||||
func attempt(w http.ResponseWriter, req *http.Request) {
|
func attempt(w http.ResponseWriter, req *http.Request) {
|
||||||
operation := "+"
|
operation := "+"
|
||||||
if r := rand.Intn(2); r == 0 {
|
if r := rand.Intn(2); r == 0 {
|
||||||
operation = "-"
|
operation = "-"
|
||||||
}
|
}
|
||||||
|
|
||||||
r := map[string]string{
|
first := rand.Intn(MAX)
|
||||||
"operation": operation,
|
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)
|
b, err := json.Marshal(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
2
main.go
2
main.go
@ -9,6 +9,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const MAX = 12
|
||||||
|
|
||||||
var addr = flag.String("addr", ":8000", "address I'll listen on.")
|
var addr = flag.String("addr", ":8000", "address I'll listen on.")
|
||||||
var static_files = flag.String("static", "./static", "location of static files")
|
var static_files = flag.String("static", "./static", "location of static files")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user