diff options
| author | Saumit Dinesan <justsaumit@protonmail.com> | 2023-09-07 22:04:12 +0530 | 
|---|---|---|
| committer | Saumit Dinesan <justsaumit@protonmail.com> | 2023-09-07 22:04:12 +0530 | 
| commit | a3ead3d67520704eda55a74841b00d5766728fab (patch) | |
| tree | a66f042970f48d188e94b746be7641e0ef91d7b1 | |
| parent | 48979e3f848ab0159156f87823bc8f3358925523 (diff) | |
Correctly formatting source files using go fmt
| -rw-r--r-- | hasher/blake2-hash_generator.go | 40 | ||||
| -rw-r--r-- | server.go | 90 | 
2 files changed, 65 insertions, 65 deletions
| diff --git a/hasher/blake2-hash_generator.go b/hasher/blake2-hash_generator.go index 4d85a58..e71a736 100644 --- a/hasher/blake2-hash_generator.go +++ b/hasher/blake2-hash_generator.go @@ -1,30 +1,30 @@  package hasher  import ( -    "fmt" -    "golang.org/x/crypto/blake2b" -    "io" -    "os" +	"fmt" +	"golang.org/x/crypto/blake2b" +	"io" +	"os"  )  func CalculateBLAKE2Hash(filePath string) (string, error) { -    file, err := os.Open(filePath) -    if err != nil { -        return "", err -    } -    defer file.Close() +	file, err := os.Open(filePath) +	if err != nil { +		return "", err +	} +	defer file.Close() -    hash, err := blake2b.New256(nil) -    if err != nil { -        return "", err -    } +	hash, err := blake2b.New256(nil) +	if err != nil { +		return "", err +	} -    _, err = io.Copy(hash, file) -    if err != nil { -        return "", err -    } +	_, err = io.Copy(hash, file) +	if err != nil { +		return "", err +	} -    hashBytes := hash.Sum(nil) -    hashString := fmt.Sprintf("%x", hashBytes) -    return hashString, nil +	hashBytes := hash.Sum(nil) +	hashString := fmt.Sprintf("%x", hashBytes) +	return hashString, nil  } @@ -1,13 +1,13 @@  package main  import ( -  "net/http" +	"net/http" -  "github.com/labstack/echo/v4" +	"github.com/labstack/echo/v4" -  "fmt" -  "github.com/justsaumit/go-fic-api/idgen" -  "github.com/justsaumit/go-fic-api/hasher" +	"fmt" +	"github.com/justsaumit/go-fic-api/hasher" +	"github.com/justsaumit/go-fic-api/idgen"  )  type HelloWorld struct { @@ -15,29 +15,29 @@ type HelloWorld struct {  }  func main() { -  e := echo.New() -  e.GET("/hello", Greetings) +	e := echo.New() +	e.GET("/hello", Greetings)  	e.GET("/hello/:name", GreetingsWithParams)  	e.GET("/hello-queries", GreetingsWithQuery) -  e.GET("/genid", GenerateIDHandler) -  e.GET("/hasher", hasherHandler) -  e.GET("/", func(c echo.Context) error { -    return c.String(http.StatusOK, "Hello, World!") -  }) -  e.Logger.Fatal(e.Start(":3000")) +	e.GET("/genid", GenerateIDHandler) +	e.GET("/hasher", hasherHandler) +	e.GET("/", func(c echo.Context) error { +		return c.String(http.StatusOK, "Hello, World!") +	}) +	e.Logger.Fatal(e.Start(":3000"))  }  func Greetings(c echo.Context) error { -  return c.JSON(http.StatusOK, HelloWorld{ -    Message: "Hello World", -  }) +	return c.JSON(http.StatusOK, HelloWorld{ +		Message: "Hello World", +	})  }  func GreetingsWithParams(c echo.Context) error { -  params := c.Param("name") -  return c.JSON(http.StatusOK, HelloWorld{ -    Message: "Hello World, my name is " + params, -  }) +	params := c.Param("name") +	return c.JSON(http.StatusOK, HelloWorld{ +		Message: "Hello World, my name is " + params, +	})  }  func GreetingsWithQuery(c echo.Context) error { @@ -48,35 +48,35 @@ func GreetingsWithQuery(c echo.Context) error {  }  func GenerateIDHandler(c echo.Context) error { -    id := idgen.GenerateID() -    //Print the generated ID to the console. -    fmt.Println("Generated ID:", id) -    return c.JSON(http.StatusOK, map[string]string{"message": "Generated ID: " + id}) -    //  return c.JSON(http.StatusOK, HelloWorld{ -    //  Message: "Generated ID: " + id, -    //}) +	id := idgen.GenerateID() +	//Print the generated ID to the console. +	fmt.Println("Generated ID:", id) +	return c.JSON(http.StatusOK, map[string]string{"message": "Generated ID: " + id}) +	//  return c.JSON(http.StatusOK, HelloWorld{ +	//  Message: "Generated ID: " + id, +	//})  }  func hasherHandler(c echo.Context) error { -  filePaths := []string{ -    "./message-orig.txt", -    "./message-copy.txt", -    "./message-modd.txt", -  } -  hashResults := make(map[string]string) +	filePaths := []string{ +		"./message-orig.txt", +		"./message-copy.txt", +		"./message-modd.txt", +	} +	hashResults := make(map[string]string) -  for _, filePath := range filePaths { -      hash, err := hasher.CalculateBLAKE2Hash(filePath) -      if err != nil { -          return c.String(http.StatusInternalServerError, "Error calculating hash") -      } -      hashResults[filePath] = hash -  } +	for _, filePath := range filePaths { +		hash, err := hasher.CalculateBLAKE2Hash(filePath) +		if err != nil { +			return c.String(http.StatusInternalServerError, "Error calculating hash") +		} +		hashResults[filePath] = hash +	} -  response := "BLAKE2b hashes:\n" -  for filePath, hash := range hashResults { -      response += fmt.Sprintf("%s: %s\n", filePath, hash) -  } +	response := "BLAKE2b hashes:\n" +	for filePath, hash := range hashResults { +		response += fmt.Sprintf("%s: %s\n", filePath, hash) +	} -  return c.String(http.StatusOK, response) +	return c.String(http.StatusOK, response)  } | 
