mirror of
https://github.com/aykhans/dodo.git
synced 2025-04-21 11:16:47 +00:00
Compare commits
8 Commits
39d366aadb
...
8d7aae4a61
Author | SHA1 | Date | |
---|---|---|---|
8d7aae4a61 | |||
0725c1a481 | |||
e3cbe1e9b4 | |||
94211eb018 | |||
565079fe97 | |||
696176e611 | |||
9ea06593f9 | |||
7f7dc07f4c |
86
.github/workflows/publish-docker-image.yml
vendored
Normal file
86
.github/workflows/publish-docker-image.yml
vendored
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
name: publish-docker-image
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
# Match stable and pre versions, such as 'v1.0.0', 'v0.23.0-a', 'v0.23.0-a.2', 'v0.23.0-b', 'v0.23.0-b.3'
|
||||||
|
- "v*.*.*"
|
||||||
|
- "v*.*.*-a"
|
||||||
|
- "v*.*.*-a.*"
|
||||||
|
- "v*.*.*-b"
|
||||||
|
- "v*.*.*-b.*"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-push-stable-image:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v3
|
||||||
|
|
||||||
|
- name: Extract build args
|
||||||
|
# Extract version number and check if it's an pre version
|
||||||
|
run: |
|
||||||
|
if [[ "${GITHUB_REF_NAME}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
||||||
|
echo "PRE_RELEASE=false" >> $GITHUB_ENV
|
||||||
|
else
|
||||||
|
echo "PRE_RELEASE=true" >> $GITHUB_ENV
|
||||||
|
fi
|
||||||
|
echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Login to Docker Hub
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
username: aykhans
|
||||||
|
password: ${{ secrets.DOCKER_TOKEN }}
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
id: buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
with:
|
||||||
|
install: true
|
||||||
|
version: v0.9.1
|
||||||
|
|
||||||
|
# Metadata for stable versions
|
||||||
|
- name: Docker meta for stable
|
||||||
|
id: meta-stable
|
||||||
|
if: env.PRE_RELEASE == 'false'
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: |
|
||||||
|
aykhans/dodo
|
||||||
|
tags: |
|
||||||
|
type=semver,pattern={{version}},value=${{ env.VERSION }}
|
||||||
|
type=raw,value=stable
|
||||||
|
flavor: |
|
||||||
|
latest=true
|
||||||
|
labels: |
|
||||||
|
org.opencontainers.image.version=${{ env.VERSION }}
|
||||||
|
|
||||||
|
# Metadata for pre versions
|
||||||
|
- name: Docker meta for pre
|
||||||
|
id: meta-pre
|
||||||
|
if: env.PRE_RELEASE == 'true'
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: |
|
||||||
|
aykhans/dodo
|
||||||
|
tags: |
|
||||||
|
type=raw,value=${{ env.VERSION }}
|
||||||
|
labels: |
|
||||||
|
org.opencontainers.image.version=${{ env.VERSION }}
|
||||||
|
|
||||||
|
- name: Build and Push
|
||||||
|
id: docker_build
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: ./
|
||||||
|
file: ./Dockerfile
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta-stable.outputs.tags || steps.meta-pre.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta-stable.outputs.labels || steps.meta-pre.outputs.labels }}
|
@ -1,4 +1,4 @@
|
|||||||
FROM golang:1.22.6-alpine AS builder
|
FROM golang:1.23.2-alpine AS builder
|
||||||
|
|
||||||
WORKDIR /dodo
|
WORKDIR /dodo
|
||||||
|
|
||||||
|
2
go.mod
2
go.mod
@ -1,6 +1,6 @@
|
|||||||
module github.com/aykhans/dodo
|
module github.com/aykhans/dodo
|
||||||
|
|
||||||
go 1.22.6
|
go 1.23.2
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/go-playground/validator/v10 v10.23.0
|
github.com/go-playground/validator/v10 v10.23.0
|
||||||
|
2
main.go
2
main.go
@ -81,7 +81,7 @@ func main() {
|
|||||||
Proxies: jsonConf.Proxies,
|
Proxies: jsonConf.Proxies,
|
||||||
Body: jsonConf.Body,
|
Body: jsonConf.Body,
|
||||||
Yes: cliConf.Yes,
|
Yes: cliConf.Yes,
|
||||||
NoProxyCheck: *conf.NoProxyCheck.ValueOrPanic(),
|
NoProxyCheck: conf.NoProxyCheck.ValueOrPanic(),
|
||||||
}
|
}
|
||||||
requestConf.Print()
|
requestConf.Print()
|
||||||
if !cliConf.Yes {
|
if !cliConf.Yes {
|
||||||
|
@ -5,20 +5,20 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type NonNilConcrete interface {
|
type NonNilT interface {
|
||||||
~int | ~float64 | ~string | ~bool
|
~int | ~float64 | ~string | ~bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type Option[T NonNilConcrete] interface {
|
type Option[T NonNilT] interface {
|
||||||
IsNone() bool
|
IsNone() bool
|
||||||
ValueOrErr() (*T, error)
|
ValueOrErr() (T, error)
|
||||||
ValueOr(def *T) *T
|
ValueOr(def T) T
|
||||||
ValueOrPanic() *T
|
ValueOrPanic() T
|
||||||
UnmarshalJSON(data []byte) error
|
UnmarshalJSON(data []byte) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't call this struct directly, use NewOption[T] or NewNoneOption[T] instead.
|
// Don't call this struct directly, use NewOption[T] or NewNoneOption[T] instead.
|
||||||
type option[T NonNilConcrete] struct {
|
type option[T NonNilT] struct {
|
||||||
// value holds the actual value of the Option if it is not None.
|
// value holds the actual value of the Option if it is not None.
|
||||||
value T
|
value T
|
||||||
// none indicates whether the Option is None (i.e., has no value).
|
// none indicates whether the Option is None (i.e., has no value).
|
||||||
@ -29,28 +29,39 @@ func (o *option[T]) IsNone() bool {
|
|||||||
return o.none
|
return o.none
|
||||||
}
|
}
|
||||||
|
|
||||||
// The returned value can be nil, if the Option is None, it will return nil and an error.
|
// If the Option is None, it will return zero value of the type and an error.
|
||||||
func (o *option[T]) ValueOrErr() (*T, error) {
|
func (o *option[T]) ValueOrErr() (T, error) {
|
||||||
if o.IsNone() {
|
if o.IsNone() {
|
||||||
return nil, errors.New("Option is None")
|
return o.value, errors.New("Option is None")
|
||||||
}
|
}
|
||||||
return &o.value, nil
|
return o.value, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// The returned value can't be nil, if the Option is None, it will return the default value.
|
// If the Option is None, it will return the default value.
|
||||||
func (o *option[T]) ValueOr(def *T) *T {
|
func (o *option[T]) ValueOr(def T) T {
|
||||||
if o.IsNone() {
|
if o.IsNone() {
|
||||||
return def
|
return def
|
||||||
}
|
}
|
||||||
return &o.value
|
return o.value
|
||||||
}
|
}
|
||||||
|
|
||||||
// The returned value can't be nil, if the Option is None, it will panic.
|
// If the Option is None, it will panic.
|
||||||
func (o *option[T]) ValueOrPanic() *T {
|
func (o *option[T]) ValueOrPanic() T {
|
||||||
if o.IsNone() {
|
if o.IsNone() {
|
||||||
panic("Option is None")
|
panic("Option is None")
|
||||||
}
|
}
|
||||||
return &o.value
|
return o.value
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *option[T]) SetValue(value T) {
|
||||||
|
o.value = value
|
||||||
|
o.none = false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *option[T]) SetNone() {
|
||||||
|
var zeroValue T
|
||||||
|
o.value = zeroValue
|
||||||
|
o.none = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *option[T]) UnmarshalJSON(data []byte) error {
|
func (o *option[T]) UnmarshalJSON(data []byte) error {
|
||||||
@ -62,10 +73,10 @@ func (o *option[T]) UnmarshalJSON(data []byte) error {
|
|||||||
return json.Unmarshal(data, &o.value)
|
return json.Unmarshal(data, &o.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewOption[T NonNilConcrete](value T) *option[T] {
|
func NewOption[T NonNilT](value T) *option[T] {
|
||||||
return &option[T]{value: value}
|
return &option[T]{value: value}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNoneOption[T NonNilConcrete]() *option[T] {
|
func NewNoneOption[T NonNilT]() *option[T] {
|
||||||
return &option[T]{none: true}
|
return &option[T]{none: true}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user