Update deps

This commit is contained in:
Frank Denis 2018-03-07 18:29:26 +01:00
parent 75f3c6403b
commit d8f502f130
7 changed files with 132 additions and 19 deletions

16
Gopkg.lock generated
View File

@ -94,6 +94,12 @@
packages = ["."]
revision = "52c32ac39e436cd9295a4629a91f0613ce67052f"
[[projects]]
branch = "master"
name = "github.com/jedisct1/go-clocksmith"
packages = ["."]
revision = "cd58e2ceb29bcb6568281e33a1166f55d2d80188"
[[projects]]
branch = "master"
name = "github.com/jedisct1/go-minisign"
@ -116,7 +122,7 @@
branch = "master"
name = "github.com/kardianos/service"
packages = ["."]
revision = "89346fbadecfd8c0ca98cfd31523f8eba9b4abbf"
revision = "0ab6efe2ea51f0531a8ceaaa33416b3aab844c28"
[[projects]]
name = "github.com/miekg/dns"
@ -128,7 +134,7 @@
branch = "master"
name = "github.com/pquerna/cachecontrol"
packages = ["cacheobject"]
revision = "0dec1b30a0215bb68605dfc568e8855066c9202d"
revision = "525d0eb5f91d30e3b1548de401b7ef9ea6898520"
[[projects]]
branch = "master"
@ -142,7 +148,7 @@
"poly1305",
"salsa20/salsa"
]
revision = "91a49db82a88618983a78a06c1cbd4e00ab749ab"
revision = "85f98707c97e11569271e4d9b3d397e079c4f4d0"
[[projects]]
branch = "master"
@ -154,7 +160,7 @@
"ipv4",
"ipv6"
]
revision = "22ae77b79946ea320088417e4d50825671d82d57"
revision = "d25186b37f34ebdbbea8f488ef055638dfab272d"
[[projects]]
branch = "master"
@ -177,6 +183,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "32f9b1bb4dd9f1ca13e9daedf85fc6cc9f3a97a023171a32ac7a2144ba9c1956"
inputs-digest = "5305be9b7e7f5f7d400b08b3b175eda810ccb13aa04049ff7efd58c13c04a809"
solver-name = "gps-cdcl"
solver-version = 1

View File

@ -65,3 +65,7 @@
[[constraint]]
name = "gopkg.in/natefinch/lumberjack.v2"
version = "2.1.0"
[[constraint]]
branch = "master"
name = "github.com/jedisct1/go-clocksmith"

View File

@ -3,10 +3,9 @@ go_import_path: github.com/kardianos/service
sudo: required
go:
- 1.6.x
- 1.7.x
- 1.8.x
- 1.9.x
- "1.10"
- master
before_install:

View File

@ -8,6 +8,7 @@
package service_test
import (
"flag"
"fmt"
"io/ioutil"
"log"
@ -23,17 +24,18 @@ import (
const runAsServiceArg = "RunThisAsService"
func TestMain(m *testing.M) {
if len(os.Args) == 2 {
reportDir := flag.String("su.reportDir", "", "")
runAsService := flag.Bool("su.runAsService", false, "")
flag.Parse()
if !*runAsService {
os.Exit(m.Run())
} else if len(os.Args) == 4 && os.Args[2] == runAsServiceArg {
reportDir := os.Args[3]
writeReport(reportDir, "call")
runService()
writeReport(reportDir, "finished")
os.Exit(0)
}
log.Fatalf("Invalid arguments: %v", os.Args)
if len(*reportDir) == 0 {
log.Fatal("missing su.reportDir argument")
}
writeReport(*reportDir, "call")
runService()
writeReport(*reportDir, "finished")
}
func TestInstallRunRestartStopRemove(t *testing.T) {
@ -168,7 +170,7 @@ func mustNewRunAsService(
) service.Service {
sc := &service.Config{
Name: "go_service_test",
Arguments: []string{"-test.v=true", runAsServiceArg, reportDir},
Arguments: []string{"-test.v=true", "-su.runAsService", "-su.reportDir", reportDir},
}
s, err := service.New(p, sc)
if err != nil {

View File

@ -9,6 +9,8 @@ import (
"fmt"
"os"
"os/signal"
"regexp"
"strconv"
"text/template"
"time"
)
@ -54,6 +56,47 @@ func (s *upstart) configPath() (cp string, err error) {
cp = "/etc/init/" + s.Config.Name + ".conf"
return
}
func (s *upstart) hasKillStanza() bool {
defaultValue := true
out, err := exec.Command("/sbin/init", "--version").Output()
if err != nil {
return defaultValue
}
re := regexp.MustCompile(`init \(upstart (\d+.\d+.\d+)\)`)
matches := re.FindStringSubmatch(string(out))
if len(matches) != 2 {
return defaultValue
}
version := make([]int, 3)
for idx, vStr := range strings.Split(matches[1], ".") {
version[idx], err = strconv.Atoi(vStr)
if err != nil {
return defaultValue
}
}
maxVersion := []int{0, 6, 5}
if versionAtMost(version, maxVersion) {
return false
}
return defaultValue
}
func versionAtMost(version, max []int) bool {
for idx, m := range max {
v := version[idx]
if v > m {
return false
}
}
return true
}
func (s *upstart) template() *template.Template {
return template.Must(template.New("").Funcs(tf).Parse(upstartScript))
}
@ -81,10 +124,12 @@ func (s *upstart) Install() error {
var to = &struct {
*Config
Path string
Path string
HasKillStanza bool
}{
s.Config,
path,
s.hasKillStanza(),
}
return s.template().Execute(f, to)
@ -149,7 +194,7 @@ const upstartScript = `# {{.Description}}
{{if .DisplayName}}description "{{.DisplayName}}"{{end}}
kill signal INT
{{if .HasKillStanza}}kill signal INT{{end}}
{{if .ChRoot}}chroot {{.ChRoot}}{{end}}
{{if .WorkingDirectory}}chdir {{.WorkingDirectory}}{{end}}
start on filesystem or runlevel [2345]

View File

@ -41,6 +41,10 @@ var (
ErrMustRevalidateNoArgs = errors.New("Unexpected argument to `must-revalidate`")
ErrPublicNoArgs = errors.New("Unexpected argument to `public`")
ErrProxyRevalidateNoArgs = errors.New("Unexpected argument to `proxy-revalidate`")
// Experimental
ErrImmutableNoArgs = errors.New("Unexpected argument to `immutable`")
ErrStaleIfErrorDeltaSeconds = errors.New("Failed to parse delta-seconds in `stale-if-error`")
ErrStaleWhileRevalidateDeltaSeconds = errors.New("Failed to parse delta-seconds in `stale-while-revalidate`")
)
func whitespace(b byte) bool {
@ -403,6 +407,21 @@ type ResponseCacheDirectives struct {
// proxy-revalidate response directive.
SMaxAge DeltaSeconds
////
// Experimental features
// - https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#Extension_Cache-Control_directives
// - https://www.fastly.com/blog/stale-while-revalidate-stale-if-error-available-today
////
// immutable(cast-to-bool): experimental feature
Immutable bool
// stale-if-error(delta seconds): experimental feature
StaleIfError DeltaSeconds
// stale-while-revalidate(delta seconds): experimental feature
StaleWhileRevalidate DeltaSeconds
// Extensions: http://tools.ietf.org/html/rfc7234#section-5.2.3
//
// The Cache-Control header field can be extended through the use of one
@ -416,6 +435,9 @@ func ParseResponseCacheControl(value string) (*ResponseCacheDirectives, error) {
cd := &ResponseCacheDirectives{
MaxAge: -1,
SMaxAge: -1,
// Exerimantal stale timeouts
StaleIfError: -1,
StaleWhileRevalidate: -1,
}
err := parse(value, cd)
@ -446,6 +468,13 @@ func (cd *ResponseCacheDirectives) addToken(token string) error {
err = ErrMaxAgeDeltaSeconds
case "s-maxage":
err = ErrSMaxAgeDeltaSeconds
// Experimental
case "immutable":
cd.Immutable = true
case "stale-if-error":
err = ErrMaxAgeDeltaSeconds
case "stale-while-revalidate":
err = ErrMaxAgeDeltaSeconds
default:
cd.Extensions = append(cd.Extensions, token)
}
@ -500,6 +529,13 @@ func (cd *ResponseCacheDirectives) addPair(token string, v string) error {
cd.MaxAge, err = parseDeltaSeconds(v)
case "s-maxage":
cd.SMaxAge, err = parseDeltaSeconds(v)
// Experimental
case "immutable":
err = ErrImmutableNoArgs
case "stale-if-error":
cd.StaleIfError, err = parseDeltaSeconds(v)
case "stale-while-revalidate":
cd.StaleWhileRevalidate, err = parseDeltaSeconds(v)
default:
// TODO(pquerna): this sucks, making user re-parse, and its technically not 'quoted' like the original,
// but this is still easier, just a SplitN on "="

View File

@ -246,6 +246,27 @@ func TestResPrivate(t *testing.T) {
require.Equal(t, cd.PrivatePresent, true)
}
func TestResImmutable(t *testing.T) {
cd, err := ParseResponseCacheControl(`immutable`)
require.NoError(t, err)
require.NotNil(t, cd)
require.Equal(t, cd.Immutable, true)
}
func TestResStaleIfError(t *testing.T) {
cd, err := ParseResponseCacheControl(`stale-if-error=99999`)
require.NoError(t, err)
require.NotNil(t, cd)
require.Equal(t, cd.StaleIfError, DeltaSeconds(99999))
}
func TestResStaleWhileRevalidate(t *testing.T) {
cd, err := ParseResponseCacheControl(`stale-while-revalidate=99999`)
require.NoError(t, err)
require.NotNil(t, cd)
require.Equal(t, cd.StaleWhileRevalidate, DeltaSeconds(99999))
}
func TestParseDeltaSecondsZero(t *testing.T) {
ds, err := parseDeltaSeconds("0")
require.NoError(t, err)