Skip to content

Commit 1b8c3a6

Browse files
committed
Refactor package
- Upgrade to Go 1.16 - Build binary for Apple Silicon - Change package path from `github.com/wabarc/archive.is/pkg` to `github.com/wabarc/archive.is` - Minor improvements - Do not redirect for wayback - Add playback func to search archived URLs - Add more tests
1 parent 3c4eba7 commit 1b8c3a6

File tree

16 files changed

+498
-363
lines changed

16 files changed

+498
-363
lines changed

.github/workflows/release.yml

+10-13
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ jobs:
4444
arch: ppc64
4545
- os: linux
4646
arch: ppc64le
47+
- os: darwin
48+
arch: arm64
4749
exclude:
4850
- os: darwin
4951
arch: 386
@@ -68,7 +70,7 @@ jobs:
6870
- name: Set up Go 1.x
6971
uses: actions/setup-go@v2
7072
with:
71-
go-version: ^1.15
73+
go-version: ^1.16
7274

7375
- name: Build fat binary
7476
id: builder
@@ -128,24 +130,19 @@ jobs:
128130
path: archive-is # Put files to archive.is directory
129131

130132
- name: Create Release
131-
uses: actions/create-release@v1
133+
uses: softprops/action-gh-release@v1
134+
if: startsWith(github.ref, 'refs/tags/')
132135
env:
133136
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
134137
with:
135-
tag_name: ${{ github.ref }}
136-
release_name: Release ${{ github.ref }}
137138
body: |
139+
See [CHANGELOG.md](https://github.com/${{ github.repository }}/blob/${{ github.sha }}/CHANGELOG.md).
140+
138141
**Digests in this release:**
139142
140143
```
141144
${{ needs.checksum.outputs.digest }}
142145
```
143-
draft: false
144-
prerelease: true
145-
146-
- name: Upload release assets
147-
uses: fnkr/github-action-ghr@v1
148-
if: startsWith(github.ref, 'refs/tags/')
149-
env:
150-
GHR_PATH: archive-is/
151-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
146+
draft: true
147+
files: |
148+
archive-is/*

Makefile

+4-8
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ export GOPROXY = https://proxy.golang.org
44
NAME = archive.is
55
BINDIR ?= ./build/binary
66
PACKDIR ?= ./build/package
7-
LDFLAGS := $(shell echo "-X 'archive.is/version.Version=`git describe --tags --abbrev=0`'")
8-
LDFLAGS := $(shell echo "${LDFLAGS} -X 'archive.is/version.Commit=`git rev-parse --short HEAD`'")
9-
LDFLAGS := $(shell echo "${LDFLAGS} -X 'archive.is/version.BuildDate=`date +%FT%T%z`'")
7+
LDFLAGS := $(shell echo "-X 'github.com/wabarc/archive.is.Version=`git describe --tags --abbrev=0`'")
108
GOBUILD ?= CGO_ENABLED=0 go build -trimpath --ldflags "-s -w ${LDFLAGS} -buildid=" -v
119
VERSION ?= $(shell git describe --tags `git rev-list --tags --max-count=1` | sed -e 's/v//g')
1210
GOFILES ?= $(wildcard ./cmd/archive.is/*.go)
@@ -15,6 +13,7 @@ PACKAGES ?= $(shell go list ./...)
1513

1614
PLATFORM_LIST = \
1715
darwin-amd64 \
16+
darwin-arm64 \
1817
linux-386 \
1918
linux-amd64 \
2019
linux-armv5 \
@@ -42,6 +41,7 @@ WINDOWS_ARCH_LIST = \
4241
.PHONY: \
4342
darwin-386 \
4443
darwin-amd64 \
44+
darwin-arm64 \
4545
linux-386 \
4646
linux-amd64 \
4747
linux-armv5 \
@@ -68,11 +68,7 @@ WINDOWS_ARCH_LIST = \
6868
releases \
6969
clean \
7070
test \
71-
fmt \
72-
rpm \
73-
debian \
74-
debian-packages \
75-
docker-image
71+
fmt
7672

7773
darwin-386:
7874
GOARCH=386 GOOS=darwin $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ $(GOFILES)

cmd/archive.is/is.go

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"os"
7+
8+
"github.com/wabarc/archive.is"
9+
)
10+
11+
func main() {
12+
var (
13+
playback bool
14+
version bool
15+
)
16+
17+
const playbackHelp = "Search archived URL"
18+
const versionHelp = "Show version"
19+
20+
flag.BoolVar(&playback, "playback", false, playbackHelp)
21+
flag.BoolVar(&playback, "p", false, playbackHelp)
22+
flag.BoolVar(&version, "version", false, versionHelp)
23+
flag.BoolVar(&version, "v", false, versionHelp)
24+
flag.Parse()
25+
26+
if version {
27+
fmt.Println(is.Version)
28+
os.Exit(0)
29+
}
30+
31+
args := flag.Args()
32+
if len(args) < 1 {
33+
flag.Usage()
34+
e := os.Args[0]
35+
fmt.Printf(" %s url [url]\n\n", e)
36+
fmt.Printf("example:\n %s https://example.com https://example.org\n\n", e)
37+
os.Exit(1)
38+
}
39+
40+
wbrc := &is.Archiver{}
41+
42+
if playback {
43+
collects, _ := wbrc.Playback(args)
44+
for orig, dest := range collects {
45+
fmt.Println(orig, "=>", dest)
46+
}
47+
os.Exit(0)
48+
}
49+
50+
saved, _ := wbrc.Wayback(args)
51+
for orig, dest := range saved {
52+
fmt.Println(orig, "=>", dest)
53+
}
54+
}

cmd/is.go

-28
This file was deleted.

pkg/doc.go renamed to doc.go

File renamed without changes.

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ require (
77
github.com/cretz/bine v0.1.0
88
github.com/stretchr/testify v1.7.0 // indirect
99
github.com/wabarc/helper v0.0.0-20210127120855-10af37cc2616
10+
github.com/wabarc/logger v0.0.0-20210417045349-d0d82e8e99ee
1011
)

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
1313
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
1414
github.com/wabarc/helper v0.0.0-20210127120855-10af37cc2616 h1:wZ5HtpmZAVUq0Im5Sm92ycJrTeLJk5lB/Kvh55Rd+Ps=
1515
github.com/wabarc/helper v0.0.0-20210127120855-10af37cc2616/go.mod h1:N9P4r7Rn46p4nkWtXV6ztN3p5ACVnp++bgfwjTqSxQ8=
16+
github.com/wabarc/logger v0.0.0-20210417045349-d0d82e8e99ee h1:MMIp++7eem2CI1jIYDoPByMwXeZAjsFo2ciBNtvhB80=
17+
github.com/wabarc/logger v0.0.0-20210417045349-d0d82e8e99ee/go.mod h1:4uYr9fnQaQoDk1ttTzLnSB3lZm3i/vrJwN8EZIB2YuI=
1618
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
1719
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
1820
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=

0 commit comments

Comments
 (0)