Skip to content

Commit 5b8274f

Browse files
committed
all: bump to go1.15.6
1 parent 986e607 commit 5b8274f

File tree

5 files changed

+49
-41
lines changed

5 files changed

+49
-41
lines changed

config.yml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,4 @@ x:
1818
import_path: golang.design/x/*
1919
repo_path: https://github.com/golang-design/*
2020
godoc_host: https://pkg.go.dev/
21-
google_analytics: |
22-
<!-- Global site tag (gtag.js) - Google Analytics -->
23-
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-80889616-4"></script>
24-
<script>
25-
window.dataLayer = window.dataLayer || [];
26-
function gtag(){dataLayer.push(arguments);}
27-
gtag('js', new Date());
28-
gtag('config', 'UA-80889616-4');
29-
</script>
21+
google_analytics: UA-80889616-4

docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# All rights reserved. Use of this source code is governed
33
# by a MIT license that can be found in the LICENSE file.
44

5-
FROM golang:1.15.5
5+
FROM golang:1.15.6
66
WORKDIR /app
77
COPY . .
88
CMD ["/app/redir.app", "-s"]

public/x.html

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
<!DOCTYPE html>
22
<html><head>
3-
{{ .GoogleAnalytics }}
3+
<!-- Global site tag (gtag.js) - Google Analytics -->
4+
<script async src="https://www.googletagmanager.com/gtag/js?id={{ .GoogleAnalytics }}"></script>
5+
<script>
6+
window.dataLayer = window.dataLayer || [];
7+
function gtag(){dataLayer.push(arguments);}
8+
gtag('js', new Date());
9+
gtag('config', '{{ .GoogleAnalytics }}');
10+
</script>
411
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
512
<meta name="go-import" content="{{.ImportRoot}} {{.VCS}} {{.VCSRoot}}">
6-
<meta http-equiv="refresh" content="0; url=https://pkg.go.dev/{{.ImportRoot}}{{.Suffix}}">
13+
<!-- <meta http-equiv="refresh" content="0; url=https://pkg.go.dev/{{.ImportRoot}}{{.Suffix}}"> -->
714
</head><body>
8-
Redirecting to <a href="https://pkg.go.dev/{{.ImportRoot}}{{.Suffix}}">pkg.go.dev/{{.ImportRoot}}{{.Suffix}}</a>...
15+
<h1>{{.ImportRoot}}{{.Suffix}}</h1>
16+
<ul>
17+
<li>Source: <a href="https://pkg.go.dev/{{.ImportRoot}}{{.Suffix}}">pkg.go.dev/{{.ImportRoot}}{{.Suffix}}</a></li>
18+
<li>Doc: <a href="https://pkg.go.dev/{{.ImportRoot}}{{.Suffix}}">pkg.go.dev/{{.ImportRoot}}{{.Suffix}}</a></li>
19+
</ul>
920
</body></html>

redir.go

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,22 @@ var (
2222
link = flag.String("l", "", "actual link for the alias, optional for delete/fetch")
2323
)
2424

25+
func usage() {
26+
fmt.Fprintf(os.Stderr,
27+
`usage: redir [-s] [-f <file>] [-op <operator> -a <alias> -l <link>]
28+
options:
29+
`)
30+
flag.PrintDefaults()
31+
fmt.Fprintf(os.Stderr, `
32+
examples:
33+
redir -s run the redir service
34+
redir -f ./import.yml import aliases from a file
35+
redir -a alias -l link allocate new short link if possible
36+
redir -op fetch -a alias fetch alias information
37+
`)
38+
os.Exit(2)
39+
}
40+
2541
func main() {
2642
log.SetPrefix(conf.Log)
2743
log.SetFlags(log.LstdFlags | log.Lshortfile)
@@ -34,13 +50,13 @@ func main() {
3450
}
3551

3652
if *daemon {
37-
processServer()
53+
runServer()
3854
return
3955
}
40-
processCmd()
56+
runCmd()
4157
}
4258

43-
func processServer() {
59+
func runServer() {
4460
s := newServer(context.Background())
4561
s.registerHandler()
4662
log.Printf("serving %s\n", conf.Addr)
@@ -49,21 +65,7 @@ func processServer() {
4965
}
5066
}
5167

52-
func usage() {
53-
fmt.Fprintf(os.Stderr, `usage: redir [-s] [-f <file>] [-op <operator> -a <alias> -l <link>]
54-
options:
55-
`)
56-
flag.PrintDefaults()
57-
fmt.Fprintf(os.Stderr, `example:
58-
redir -s run the redir service
59-
redir -f ./import.yml import aliases from a file
60-
redir -a alias -l link allocate new short link if possible
61-
redir -op fetch -a alias fetch alias information
62-
`)
63-
os.Exit(2)
64-
}
65-
66-
func processCmd() {
68+
func runCmd() {
6769
if *fromfile != "" {
6870
shortFile(*fromfile)
6971
return

short.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,42 +72,43 @@ func shortFile(fname string) {
7272
}
7373

7474
// shortCmd processes the given alias and link with a specified op.
75-
func shortCmd(ctx context.Context, operate op, alias, link string) (retErr error) {
75+
func shortCmd(ctx context.Context, operate op, alias, link string) (err error) {
7676
s, err := newStore(conf.Store)
7777
if err != nil {
78-
return fmt.Errorf("cannot create a new alias, err: %w", err)
78+
err = fmt.Errorf("cannot create a new alias, err: %w", err)
79+
return
7980
}
8081
defer s.Close()
8182

82-
errf := func(o op, err error) {
83-
retErr = fmt.Errorf("cannot %v alias to data store, err: %w", o, err)
84-
}
83+
defer func() {
84+
if err != nil {
85+
err = fmt.Errorf("cannot %v alias to data store, err: %w", operate, err)
86+
}
87+
}()
88+
8589
switch operate {
8690
case opCreate:
8791
err = s.StoreAlias(ctx, alias, link)
8892
if err != nil {
89-
errf(opCreate, err)
9093
return
9194
}
9295
log.Printf("alias %v has been created.\n", alias)
9396
case opUpdate:
9497
err = s.UpdateAlias(ctx, alias, link)
9598
if err != nil {
96-
errf(opUpdate, err)
9799
return
98100
}
99101
log.Printf("alias %v has been updated.\n", alias)
100102
case opDelete:
101103
err = s.DeleteAlias(ctx, alias)
102104
if err != nil {
103-
errf(opDelete, err)
104105
return
105106
}
106107
log.Printf("alias %v has been deleted.\n", alias)
107108
case opFetch:
108-
r, err := s.FetchAlias(ctx, alias)
109+
var r string
110+
r, err = s.FetchAlias(ctx, alias)
109111
if err != nil {
110-
errf(opFetch, err)
111112
return
112113
}
113114
log.Println(r)
@@ -118,6 +119,7 @@ func shortCmd(ctx context.Context, operate op, alias, link string) (retErr error
118119
// sHandler redirects ...
119120
func (s *server) sHandler(w http.ResponseWriter, r *http.Request) {
120121
ctx := r.Context()
122+
121123
var err error
122124
defer func() {
123125
if err != nil {
@@ -128,6 +130,7 @@ func (s *server) sHandler(w http.ResponseWriter, r *http.Request) {
128130
http.Redirect(w, r, "/404.html", http.StatusTemporaryRedirect)
129131
}
130132
}()
133+
131134
alias := strings.TrimSuffix(strings.TrimPrefix(r.URL.Path, conf.S.Prefix), "/")
132135
if alias == "" {
133136
err = s.stats(ctx, w)

0 commit comments

Comments
 (0)