Last active
August 11, 2019 18:57
-
-
Save caesaneer/a57aec124bf921c3df75260130904fe3 to your computer and use it in GitHub Desktop.
Go Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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