Skip to content

Instantly share code, notes, and snippets.

@caesaneer
Last active August 11, 2019 18:57
Show Gist options
  • Save caesaneer/a57aec124bf921c3df75260130904fe3 to your computer and use it in GitHub Desktop.
Save caesaneer/a57aec124bf921c3df75260130904fe3 to your computer and use it in GitHub Desktop.
Go Example
package main
import (
"crypto/sha256"
"fmt"
"io/ioutil"
"net/http"
"strconv"
"github.com/labstack/echo"
)
func main() {
e := echo.New()
e.GET("/test/:data", getTest)
e.Logger.Fatal(e.Start("192.168.0.14:4000"))
}
func getTest(c echo.Context) error {
times := c.Param("data")
b, err := ioutil.ReadFile("./data/test.dat")
if err != nil {
panic(err)
}
s := ""
var n int
n, err = strconv.Atoi(times)
for i := 0; i < n; i++ {
h := sha256.New()
h.Write(b)
s = fmt.Sprintf("%x", h.Sum(nil))
}
return c.String(http.StatusOK, s)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment