From 064f71b969bb315e140ebbc887372a0d07cafa6a Mon Sep 17 00:00:00 2001 From: rosahaj Date: Sat, 6 Jan 2024 04:32:41 +0100 Subject: [PATCH] Use Config struct instead of passing values to generateCertificate --- cert.go | 6 +++--- proxy.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cert.go b/cert.go index 03b841b..5b3927e 100644 --- a/cert.go +++ b/cert.go @@ -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 @@ -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 } diff --git a/proxy.go b/proxy.go index 76224a1..9a69e53 100644 --- a/proxy.go +++ b/proxy.go @@ -169,7 +169,7 @@ func main() { } log.Println("cert and key do not exist, generating") - generateCertificate(Config.Cert, Config.Key) + generateCertificate() } server := &http.Server{