Skip to content

Commit

Permalink
Gofmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Maelkum committed Sep 12, 2023
1 parent e594494 commit ce19b1e
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 81 deletions.
3 changes: 1 addition & 2 deletions cmd/keyforge/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const (
peerIDFileName = "peerid.txt"
privKeyPermissions = 0600
pubKeyPermissions = 0644

)

func main() {
Expand Down Expand Up @@ -60,7 +59,7 @@ func main() {
if flagPublicKey != "" && flagMessage != "" && flagSignature != "" {
VerifyGivenSignature(flagPublicKey, flagMessage, flagSignature)
}

if flagPeerID != "" && flagMessage != "" && flagSignature != "" {
VerifyGivenSignatureWithPeerID(flagPeerID, flagMessage, flagSignature)
}
Expand Down
132 changes: 66 additions & 66 deletions cmd/manager/bin.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,68 +15,68 @@ import (
)

func installBinary(url, folder string) {
usr, err := user.Current()
if err != nil {
log.Fatal(err)
}

targetPath := filepath.Join(usr.HomeDir, folder)
os.MkdirAll(targetPath, os.ModePerm)

resp, err := http.Get(url)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()

archiveData, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}

gzipReader, err := gzip.NewReader(bytes.NewReader(archiveData))
if err != nil {
log.Fatal(err)
}
defer gzipReader.Close()

tarReader := tar.NewReader(gzipReader)

for {
header, err := tarReader.Next()
if err == io.EOF {
break
}
if err != nil {
log.Fatal(err)
}

path := filepath.Join(targetPath, header.Name)
switch header.Typeflag {
case tar.TypeDir:
if err := os.MkdirAll(path, os.FileMode(header.Mode)); err != nil {
log.Fatal(err)
}

case tar.TypeReg:
outFile, err := os.Create(path)
if err != nil {
log.Fatal(err)
}

if _, err := io.Copy(outFile, tarReader); err != nil {
log.Fatal(err)
}

outFile.Close()

if err := os.Chmod(path, os.FileMode(header.Mode)); err != nil {
log.Fatal(err)
}

log.Printf("File %s installed in %s", header.Name, targetPath)
}
}
usr, err := user.Current()
if err != nil {
log.Fatal(err)
}

targetPath := filepath.Join(usr.HomeDir, folder)
os.MkdirAll(targetPath, os.ModePerm)

resp, err := http.Get(url)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()

archiveData, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}

gzipReader, err := gzip.NewReader(bytes.NewReader(archiveData))
if err != nil {
log.Fatal(err)
}
defer gzipReader.Close()

tarReader := tar.NewReader(gzipReader)

for {
header, err := tarReader.Next()
if err == io.EOF {
break
}
if err != nil {
log.Fatal(err)
}

path := filepath.Join(targetPath, header.Name)
switch header.Typeflag {
case tar.TypeDir:
if err := os.MkdirAll(path, os.FileMode(header.Mode)); err != nil {
log.Fatal(err)
}

case tar.TypeReg:
outFile, err := os.Create(path)
if err != nil {
log.Fatal(err)
}

if _, err := io.Copy(outFile, tarReader); err != nil {
log.Fatal(err)
}

outFile.Close()

if err := os.Chmod(path, os.FileMode(header.Mode)); err != nil {
log.Fatal(err)
}

log.Printf("File %s installed in %s", header.Name, targetPath)
}
}
}

func installB7s(baseURL, version string) {
Expand Down Expand Up @@ -105,18 +105,18 @@ func installRuntime(baseURL, version string) {
arch := runtime.GOARCH
platform := runtime.GOOS

if(platform == "darwin") {
if platform == "darwin" {
platform = "macos"
}

if(arch == "amd64") {
if arch == "amd64" {
arch = "x86_64"
}

if(arch == "arm64") {
if arch == "arm64" {
arch = "aarch64"
}

url := fmt.Sprintf("%s/%s/blockless-runtime.%s-latest.%s.tar.gz", baseURL, version, platform, arch)
installBinary(url, ".b7s/runtime")
}
}
21 changes: 9 additions & 12 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func main() {
<-ctx.Done()
}


func makeBasicHost(listenPort int, insecure bool, privKeyPath string) (host.Host, error) {
priv, err := loadPrivateKey(privKeyPath)
if err != nil {
Expand All @@ -76,20 +75,18 @@ func makeBasicHost(listenPort int, insecure bool, privKeyPath string) (host.Host
return libp2p.New(opts...)
}



func loadPrivateKey(filePath string) (crypto.PrivKey, error) {
keyBytes, err := ioutil.ReadFile(filePath)
if err != nil {
return nil, err
}
keyBytes, err := ioutil.ReadFile(filePath)
if err != nil {
return nil, err
}

priv, err := crypto.UnmarshalPrivateKey(keyBytes)
if err != nil {
return nil, err
}
priv, err := crypto.UnmarshalPrivateKey(keyBytes)
if err != nil {
return nil, err
}

return priv, nil
return priv, nil
}

func getHostAddress(ha host.Host) string {
Expand Down
2 changes: 1 addition & 1 deletion cmd/manager/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,4 @@ func removeMacOSService() {

func removeWindowsService() {
log.Fatal("Removing a service on Windows is not supported in this code.")
}
}

0 comments on commit ce19b1e

Please sign in to comment.