cmd/admingolangorg: update deployment to Go 1.16
Include a placeholder and initial value to clarify key/target inputs,
update 'golang.org' to 'go.dev', and use embed for the HTML template.
Also rewrite .gcloudignore to more effectively include only the bare
minimum files, hopefully in a way that won't get outdated as quickly.
Change-Id: Ic7b39fb6d8e54f93e657aae20bc4fd51c75039f4
Reviewed-on: https://go-review.googlesource.com/c/website/+/406374
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
diff --git a/cmd/admingolangorg/.gcloudignore b/cmd/admingolangorg/.gcloudignore
index 199e6d9..1f1631b 100644
--- a/cmd/admingolangorg/.gcloudignore
+++ b/cmd/admingolangorg/.gcloudignore
@@ -1,25 +1,15 @@
-# This file specifies files that are *not* uploaded to Google Cloud Platform
-# using gcloud. It follows the same syntax as .gitignore, with the addition of
-# "#!include" directives (which insert the entries of the given .gitignore-style
-# file at that point).
-#
-# For more information, run:
-# $ gcloud topic gcloudignore
-#
-.gcloudignore
-# If you would like to upload your .git directory, .gitignore file or files
-# from your .gitignore file, remove the corresponding line
-# below:
-.git
-.gitignore
+# The admingolangorg program needs a fairly short list of things
+# from the golang.org/x/website repository that probably doesn't
+# change often. Filter everything else out implicitly as long as
+# this approach needs less maintenance.
+**
+!go.mod
+!go.sum
+!cmd/
+!cmd/admingolangorg/**
+!internal/
+!internal/short/**
+!internal/memcache/**
+!internal/backport/**
-# Binaries for programs and plugins
-*.exe
-*.exe~
-*.dll
-*.so
-*.dylib
-# Test binary, build with `go test -c`
-*.test
-# Output of the go coverage tool, specifically when used with LiteIDE
-*.out
\ No newline at end of file
+.gcloudignore
diff --git a/cmd/admingolangorg/README.md b/cmd/admingolangorg/README.md
index 108b8ea..af4f7b3 100644
--- a/cmd/admingolangorg/README.md
+++ b/cmd/admingolangorg/README.md
@@ -1,6 +1,6 @@
# admingolangorg
-This app serves as the [admin interface](https://admin-dot-golang-org.appspot.com) for the golang.org/s link
+This app serves as the [admin interface](https://admin-dot-golang-org.appspot.com) for the go.dev/s link
shortener. Its functionality may be expanded in the future.
## Deployment:
@@ -8,5 +8,5 @@
To update the public site, run:
```
-gcloud app --account=username@domain.com --project=golang-org deploy app.yaml
+gcloud app --project=golang-org deploy --promote app.yaml
```
diff --git a/cmd/admingolangorg/app.yaml b/cmd/admingolangorg/app.yaml
index 6006441..9c77bf9 100644
--- a/cmd/admingolangorg/app.yaml
+++ b/cmd/admingolangorg/app.yaml
@@ -1,5 +1,6 @@
-runtime: go111
+runtime: go116
service: admin
+main: ./cmd/admingolangorg
env_variables:
GOLANGORG_REDIS_ADDR: 10.0.0.4:6379 # instance "gophercache"
diff --git a/internal/short/tmpl.go b/internal/short/admin.html
similarity index 82%
rename from internal/short/tmpl.go
rename to internal/short/admin.html
index ba16298..006d25b 100644
--- a/internal/short/tmpl.go
+++ b/internal/short/admin.html
@@ -1,13 +1,12 @@
-// Copyright 2015 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
+{{/*
+ Copyright 2015 The Go Authors. All rights reserved.
+ Use of this source code is governed by a BSD-style
+ license that can be found in the LICENSE file.
+*/ -}}
-package short
-
-const templateHTML = `
<!doctype HTML>
<html lang="en">
-<title>golang.org URL shortener</title>
+<title>go.dev URL shortener</title>
<style>
* {
box-sizing: border-box;
@@ -63,8 +62,8 @@
<form method="POST">
<tr>
- <td><input type="text" name="key"{{with .New}} value="{{.Key}}"{{end}} required></td>
- <td><input type="url" name="target"{{with .New}} value="{{.Target}}"{{end}} required></td>
+ <td><input type="text" name="key"{{with .New}} value="{{.Key}}"{{end}} placeholder="better-linker" required></td>
+ <td><input type="url" name="target" value="{{with .New}}{{.Target}}{{else}}https://{{end}}" required></td>
<td><input type="submit" name="do" value="Add">
</tr>
</form>
@@ -107,4 +106,3 @@
})
});
</script>
-`
diff --git a/internal/short/short.go b/internal/short/short.go
index 7c4c798..371986e 100644
--- a/internal/short/short.go
+++ b/internal/short/short.go
@@ -10,6 +10,7 @@
import (
"context"
+ _ "embed"
"errors"
"fmt"
"log"
@@ -125,7 +126,12 @@
return s.adminHandler
}
-var adminTemplate = template.Must(template.New("admin").Parse(templateHTML))
+var (
+ adminTemplate = template.Must(template.New("admin").Parse(templateHTML))
+
+ //go:embed admin.html
+ templateHTML string
+)
// adminHandler serves an administrative interface.
// Be careful. Ensure that this handler is only be exposed to authorized users.