Skip to content

Commit

Permalink
Use Config struct instead of passing values to generateCertificate
Browse files Browse the repository at this point in the history
  • Loading branch information
rosahaj committed Jan 6, 2024
1 parent b4c1f31 commit 064f71b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"time"
)

func generateCertificate(certPath, keyPath string) error {
func generateCertificate() error {
priv, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
return err
Expand All @@ -35,14 +35,14 @@ func generateCertificate(certPath, keyPath string) error {
return err
}

certOut, err := os.Create(certPath)
certOut, err := os.Create(Config.Cert)
if err != nil {
return err
}
defer certOut.Close()
pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes})

keyOut, err := os.OpenFile(keyPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
keyOut, err := os.OpenFile(Config.Key, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func main() {
}

log.Println("cert and key do not exist, generating")
generateCertificate(Config.Cert, Config.Key)
generateCertificate()
}

server := &http.Server{
Expand Down

0 comments on commit 064f71b

Please sign in to comment.