SeraphJACK hace 3 años
padre
commit
9ee2242e72
Firmado por: SeraphJACK <seraphjack@outlook.com> ID de clave GPG: 14162B46567AB06F
Se han modificado 6 ficheros con 18 adiciones y 10 borrados
  1. +4
    -1
      go.mod
  2. +2
    -0
      go.sum
  3. +1
    -1
      http/server.go
  4. +5
    -1
      http/utils.go
  5. +5
    -6
      main.go
  6. +1
    -1
      storage/storage.go

+ 4
- 1
go.mod Ver fichero

@@ -2,4 +2,7 @@ module votes

go 1.14

require github.com/gorilla/mux v1.7.4
require (
github.com/gorilla/mux v1.7.4
github.com/thinkeridea/go-extend v1.1.1
)

+ 2
- 0
go.sum Ver fichero

@@ -1,2 +1,4 @@
github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc=
github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/thinkeridea/go-extend v1.1.1 h1:tziAAJ1Tove3VXzqtA0k0ZAP7+grafzFjRNSuG7nRbQ=
github.com/thinkeridea/go-extend v1.1.1/go.mod h1:X/tseu0kBDuDMZYPIlQCQyfljB4CltMl1lQ3gwAs3c4=

+ 1
- 1
http/server.go Ver fichero

@@ -11,7 +11,7 @@ func Start(listen string) error {

router.HandleFunc("/challenge", tellChallenge)
router.HandleFunc("/submit", handleSubmit)
router.Handle("/", http.FileServer(http.Dir("static")))
router.NotFoundHandler = http.FileServer(http.Dir("static"))

err := http.ListenAndServe(listen, router)
if err != nil {


+ 5
- 1
http/utils.go Ver fichero

@@ -1,6 +1,7 @@
package http

import (
"github.com/thinkeridea/go-extend/exnet"
"log"
"net"
"net/http"
@@ -8,7 +9,10 @@ import (
)

func getIp(r *http.Request) net.IP {
return net.ParseIP(r.Header.Get("X-Real-Ip"))
if ip := exnet.ClientIP(r); ip != "" {
return net.ParseIP(ip)
}
return net.ParseIP(exnet.ClientPublicIP(r))
}

func checkIp(ip net.IP) bool {


+ 5
- 6
main.go Ver fichero

@@ -21,17 +21,16 @@ func main() {

signal.Ignore(syscall.SIGHUP)
c := make(chan os.Signal)
signal.Notify(c, syscall.SIGTERM)
signal.Notify(c, syscall.SIGTERM, syscall.SIGINT)
go listenExit(c)

_ = http.Start(l)
}

func listenExit(c chan os.Signal) {
for true {
_ = <-c
if err := storage.Save(); err != nil {
log.Printf("error saving results: %s", err)
}
_ = <-c
if err := storage.Save(); err != nil {
log.Printf("error saving results: %s", err)
}
os.Exit(0)
}

+ 1
- 1
storage/storage.go Ver fichero

@@ -24,7 +24,7 @@ func Init() error {
}

func Save() error {
file, err := os.Open("result.json")
file, err := os.Create("result.json")
if err != nil {
return err
}


Cargando…
Cancelar
Guardar