Skip to content

Commit

Permalink
Upgrade to 1.20 golang version (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
stn1slv authored Jun 13, 2023
1 parent fc7d971 commit 7a46e37
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ jobs:
- uses: actions/checkout@v3

- name: Set up Go environment
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: 1.19
go-version: '1.20'

- name: Build
run: go build -v ./...
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up Go environment
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: 1.19
go-version: '1.20'

- name: Checkout code
uses: actions/checkout@v2
Expand Down
20 changes: 12 additions & 8 deletions tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,33 @@ package main
import (
"crypto/tls"
"crypto/x509"
"io/ioutil"
"fmt"
"os"
)

// NewTLSConfig creates a new TLS configuration for the given certificate files.
func NewTLSConfig(clientCertFile, clientKeyFile, caCertFile string) (*tls.Config, error) {
tlsConfig := tls.Config{}
var tlsConfig = &tls.Config{}

// Load client cert
cert, err := tls.LoadX509KeyPair(clientCertFile, clientKeyFile)
if err != nil {
return &tlsConfig, err
return nil, fmt.Errorf("failed to load client cert: %w", err)
}
tlsConfig.Certificates = []tls.Certificate{cert}

// Load CA cert
caCert, err := ioutil.ReadFile(caCertFile)
caCert, err := os.ReadFile(caCertFile)
if err != nil {
return &tlsConfig, err
return nil, fmt.Errorf("failed to read CA cert file: %w", err)
}

caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert)
if ok := caCertPool.AppendCertsFromPEM(caCert); !ok {
return nil, fmt.Errorf("failed to append CA cert")
}

tlsConfig.RootCAs = caCertPool

tlsConfig.BuildNameToCertificate()
return &tlsConfig, err
return tlsConfig, nil
}

0 comments on commit 7a46e37

Please sign in to comment.