Skip to content

Commit a1d08cc

Browse files
authored
refactor!: use github.com/bassosimone/runtimex (#95)
I decided to make a separate library to maximize reuse. So, let's use this library instead. BREAKING CHANGE: As a side effect, require go1.25 for building now.
1 parent a0180e7 commit a1d08cc

26 files changed

+81
-289
lines changed

.github/workflows/go.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ jobs:
1616
goversion:
1717
# The first entry of the matrix should be the
1818
# version indicated inside the `go.mod`
19-
- "1.24"
2019
- "1.25"
2120

2221
runs-on: ubuntu-latest

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ outages, misconfigurations, censorship, and performance issues.
2525

2626
## Minimum Required Go Version
2727

28-
Go 1.24.
28+
Go 1.25.
2929

3030
## Installation
3131

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
module github.com/rbmk-project/rbmk
22

3-
go 1.24.2
3+
go 1.25.5
44

55
require (
6+
github.com/bassosimone/runtimex v0.0.0-20260108162100-336f3823f6b7
67
github.com/charmbracelet/glamour v0.10.0
78
github.com/google/go-cmp v0.7.0
89
github.com/miekg/dns v1.1.70

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWp
1010
github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA=
1111
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
1212
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
13+
github.com/bassosimone/runtimex v0.0.0-20260108162100-336f3823f6b7 h1:9qKFMaKc84pZ1i7FMUGLMqo56rv4miCd4/+qlH9SWDI=
14+
github.com/bassosimone/runtimex v0.0.0-20260108162100-336f3823f6b7/go.mod h1:GDr46yuJzuDkzOMI1/9Voo3s7VmYBU/6pkuaI5FR7gE=
1315
github.com/charmbracelet/colorprofile v0.4.1 h1:a1lO03qTrSIRaK8c3JRxJDZOvhvIeSco3ej+ngLk1kk=
1416
github.com/charmbracelet/colorprofile v0.4.1/go.mod h1:U1d9Dljmdf9DLegaJ0nGZNJvoXAhayhmidOdcBwAvKk=
1517
github.com/charmbracelet/glamour v0.10.0 h1:MtZvfwsYCx8jEPFJm3rIBFIMZUfUJ765oX8V6kXldcY=

pkg/common/runtimex/runtimex.go

Lines changed: 0 additions & 54 deletions
This file was deleted.

pkg/common/runtimex/runtimex_test.go

Lines changed: 0 additions & 156 deletions
This file was deleted.

pkg/common/selfsignedcert/selfsignedcert.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"path/filepath"
1717
"time"
1818

19-
"github.com/rbmk-project/rbmk/pkg/common/runtimex"
19+
"github.com/bassosimone/runtimex"
2020
)
2121

2222
// Config contains configuration for [New].
@@ -58,21 +58,21 @@ type Cert struct {
5858
//
5959
// This method panics on failure.
6060
func (c *Cert) WriteFiles(baseDir string) {
61-
runtimex.Try0(os.WriteFile(filepath.Join(baseDir, "cert.pem"), c.CertPEM, 0600))
62-
runtimex.Try0(os.WriteFile(filepath.Join(baseDir, "key.pem"), c.KeyPEM, 0600))
61+
runtimex.PanicOnError0(os.WriteFile(filepath.Join(baseDir, "cert.pem"), c.CertPEM, 0600))
62+
runtimex.PanicOnError0(os.WriteFile(filepath.Join(baseDir, "key.pem"), c.KeyPEM, 0600))
6363
}
6464

6565
// New generates a self-signed certificate and key with SANs.
6666
//
6767
// This function panics on failure.
6868
func New(config *Config) *Cert {
6969
// Generate the private key
70-
priv := runtimex.Try1(ecdsa.GenerateKey(elliptic.P256(), rand.Reader))
70+
priv := runtimex.PanicOnError1(ecdsa.GenerateKey(elliptic.P256(), rand.Reader))
7171

7272
// Build the certificate template
7373
notBefore := time.Now()
7474
notAfter := notBefore.Add(365 * 24 * time.Hour)
75-
serialNumber := runtimex.Try1(rand.Int(rand.Reader, new(big.Int).Lsh(big.NewInt(1), 128)))
75+
serialNumber := runtimex.PanicOnError1(rand.Int(rand.Reader, new(big.Int).Lsh(big.NewInt(1), 128)))
7676
template := x509.Certificate{
7777
SerialNumber: serialNumber,
7878
Subject: pkix.Name{
@@ -91,12 +91,12 @@ func New(config *Config) *Cert {
9191
template.IPAddresses = config.IPAddrs
9292

9393
// Generate the certificate proper and encoded to PEM
94-
certDER := runtimex.Try1(x509.CreateCertificate(
94+
certDER := runtimex.PanicOnError1(x509.CreateCertificate(
9595
rand.Reader, &template, &template, &priv.PublicKey, priv))
9696
certPEM := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: certDER})
9797

9898
// Generate the private key in PEM format
99-
keyPEM := runtimex.Try1(x509.MarshalECPrivateKey(priv))
99+
keyPEM := runtimex.PanicOnError1(x509.MarshalECPrivateKey(priv))
100100
keyPEMBytes := pem.EncodeToMemory(&pem.Block{Type: "EC PRIVATE KEY", Bytes: keyPEM})
101101

102102
// Return the results

pkg/common/selfsignedcert/selfsignedcert_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"net/url"
1212
"testing"
1313

14-
"github.com/rbmk-project/rbmk/pkg/common/runtimex"
14+
"github.com/bassosimone/runtimex"
1515
"github.com/rbmk-project/rbmk/pkg/common/selfsignedcert"
1616
)
1717

@@ -22,9 +22,9 @@ func TestSelfSignedCert(t *testing.T) {
2222

2323
// 2. create a suitable TLS listener
2424
serverConfig := &tls.Config{Certificates: []tls.Certificate{
25-
runtimex.Try1(tls.X509KeyPair(cert.CertPEM, cert.KeyPEM)),
25+
runtimex.PanicOnError1(tls.X509KeyPair(cert.CertPEM, cert.KeyPEM)),
2626
}}
27-
listener := runtimex.Try1(tls.Listen("tcp", "127.0.0.1:0", serverConfig))
27+
listener := runtimex.PanicOnError1(tls.Listen("tcp", "127.0.0.1:0", serverConfig))
2828
defer listener.Close()
2929

3030
// 3. create a listening HTTP server using the testdata files
@@ -38,7 +38,7 @@ func TestSelfSignedCert(t *testing.T) {
3838

3939
// 4. create a suitable HTTP client
4040
pool := x509.NewCertPool()
41-
runtimex.Assert(pool.AppendCertsFromPEM(cert.CertPEM), "cannot append PEM cert")
41+
runtimex.Assert(pool.AppendCertsFromPEM(cert.CertPEM))
4242
clientConfig := &tls.Config{RootCAs: pool}
4343
client := &http.Client{
4444
Transport: &http.Transport{

pkg/dns/dnscore/dohttps_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import (
1313
"net/netip"
1414
"testing"
1515

16+
"github.com/bassosimone/runtimex"
1617
"github.com/miekg/dns"
1718
"github.com/rbmk-project/rbmk/pkg/common/mocks"
18-
"github.com/rbmk-project/rbmk/pkg/common/runtimex"
1919
"github.com/stretchr/testify/assert"
2020
)
2121

@@ -234,7 +234,7 @@ func TestTransport_httpClientDo(t *testing.T) {
234234
for _, tt := range tests {
235235
t.Run(tt.name, func(t *testing.T) {
236236
transport := tt.setupTransport()
237-
req := runtimex.Try1(http.NewRequest("GET", "https://example.com", nil))
237+
req := runtimex.PanicOnError1(http.NewRequest("GET", "https://example.com", nil))
238238
resp, la, ra, err := transport.httpClientDo(req)
239239
if tt.expectedError != nil {
240240
assert.Error(t, err)

pkg/dns/dnscore/example_https_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"strings"
1111
"time"
1212

13+
"github.com/bassosimone/runtimex"
1314
"github.com/miekg/dns"
14-
"github.com/rbmk-project/rbmk/pkg/common/runtimex"
1515
"github.com/rbmk-project/rbmk/pkg/dns/dnscore"
1616
)
1717

@@ -45,7 +45,7 @@ func ExampleTransport_dnsOverHTTPS() {
4545
if err := dnscore.ValidateResponse(query, resp); err != nil {
4646
log.Fatal(err)
4747
}
48-
runtimex.Assert(len(query.Question) > 0, "expected at least one question")
48+
runtimex.Assert(len(query.Question) > 0)
4949
rrs, err := dnscore.ValidAnswers(query.Question[0], resp)
5050
if err != nil {
5151
log.Fatal(err)

0 commit comments

Comments
 (0)