You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
935 B

6 years ago
  1. package main
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "log"
  6. "net/http"
  7. "github.com/fatih/color"
  8. )
  9. const PORT = "3000"
  10. type Order struct {
  11. Target string `json:"target"`
  12. Count int `json:"count"`
  13. }
  14. var currentOrder Order
  15. func getOrder(w http.ResponseWriter, r *http.Request) {
  16. jsonr, err := json.Marshal(currentOrder)
  17. if err != nil {
  18. log.Panic(err)
  19. }
  20. fmt.Fprintln(w, string(jsonr))
  21. }
  22. func handleRequests() {
  23. http.HandleFunc("/", getOrder)
  24. log.Fatal(http.ListenAndServe(":"+PORT, nil))
  25. }
  26. func main() {
  27. asciiTitle := `
  28. _____ _____ ____ _____
  29. | __ \| __ \ / __ \ / ____|
  30. __ _ ___ | | | | | | | | | | (___
  31. / _' |/ _ \| | | | | | | | | |\___ \
  32. | (_| | (_) | |__| | |__| | |__| |____) |
  33. \__, |\___/|_____/|_____/ \____/|_____/
  34. __/ |
  35. |___/ v.2
  36. `
  37. color.Blue(asciiTitle)
  38. fmt.Println("server running at port " + PORT)
  39. go consoleInput()
  40. handleRequests()
  41. }