Skip to content

Commit c738466

Browse files
authored
Docs [pkg.go.dev] Improve Documentation (#5)
- [+] refactor(csr): remove function documentation from csr.go - [+] docs(csr): add package-level documentation in docs.go with usage example
1 parent d21e5fa commit c738466

File tree

2 files changed

+37
-21
lines changed

2 files changed

+37
-21
lines changed

csr/csr.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,6 @@ import (
1414
)
1515

1616
// GenerateCSRAndPrivateKey generates a Certificate Signing Request (CSR) and a private key.
17-
//
18-
// The function takes the following parameters:
19-
// - commonName: The common name (domain name) for the certificate.
20-
// - dnsNames: A slice of Subject Alternative Names (SANs) for the certificate.
21-
//
22-
// The function returns the following:
23-
// - csrPEM: The generated CSR in PEM format.
24-
// - privateKeyPEM: The generated private key in PEM format.
25-
// - err: An error, if any occurred during the generation process.
26-
//
27-
// The function generates an ECDSA private key using the P-256 curve and creates a CSR template
28-
// with the provided common name and SANs. The CSR is signed using the private key and encoded
29-
// in PEM format. The private key is also encoded in PEM format.
30-
//
31-
// Example usage:
32-
//
33-
// csrPEM, privateKeyPEM, err := GenerateCSRAndPrivateKey("example.com", []string{"www.example.com", "api.example.com"})
34-
// if err != nil {
35-
// // Handle the error
36-
// }
37-
// // Use csrPEM and privateKeyPEM for further processing or saving to files
3817
func GenerateCSRAndPrivateKey(commonName string, dnsNames []string) (csrPEM, privateKeyPEM []byte, err error) {
3918
// Generate a new ECDSA key pair using the P-256 curve
4019
privateKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)

csr/docs.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,41 @@
33
// License: BSD 3-Clause License
44

55
// Package csr provides functionality for generating Certificate Signing Requests (CSRs) and private keys.
6+
//
7+
// The package exports a single function, [GenerateCSRAndPrivateKey], which generates an ECDSA private key
8+
// using the P-256 curve and creates a CSR template with the provided common name and Subject Alternative
9+
// Names (SANs). The CSR is signed using the private key and encoded in PEM format. The private key is also
10+
// encoded in PEM format.
11+
//
12+
// # Usage
13+
//
14+
// The [GenerateCSRAndPrivateKey] function takes the following parameters:
15+
// - commonName: The common name (domain name) for the certificate.
16+
// - dnsNames: A slice of Subject Alternative Names (SANs) for the certificate.
17+
//
18+
// The function returns the following:
19+
// - csrPEM: The generated CSR in PEM format.
20+
// - privateKeyPEM: The generated private key in PEM format.
21+
// - err: An error, if any occurred during the generation process.
22+
//
23+
// Example:
24+
//
25+
// commonName := "example.com"
26+
// dnsNames := []string{"www.example.com", "api.example.com"}
27+
//
28+
// csrPEM, privateKeyPEM, err := csr.GenerateCSRAndPrivateKey(commonName, dnsNames)
29+
// if err != nil {
30+
// log.Fatalf("Failed to generate CSR and private key: %v", err)
31+
// }
32+
//
33+
// // Save the CSR and private key to files
34+
// err = os.WriteFile("example.com.csr.pem", csrPEM, 0644)
35+
// if err != nil {
36+
// log.Fatalf("Failed to write CSR to file: %v", err)
37+
// }
38+
//
39+
// err = os.WriteFile("example.com.key.pem", privateKeyPEM, 0600)
40+
// if err != nil {
41+
// log.Fatalf("Failed to write private key to file: %v", err)
42+
// }
643
package csr

0 commit comments

Comments
 (0)