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

View File

@ -65,3 +65,7 @@
[[constraint]] [[constraint]]
name = "gopkg.in/natefinch/lumberjack.v2" name = "gopkg.in/natefinch/lumberjack.v2"
version = "2.1.0" 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 sudo: required
go: go:
- 1.6.x
- 1.7.x
- 1.8.x - 1.8.x
- 1.9.x - 1.9.x
- "1.10"
- master - master
before_install: before_install:

View File

@ -8,6 +8,7 @@
package service_test package service_test
import ( import (
"flag"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log" "log"
@ -23,17 +24,18 @@ import (
const runAsServiceArg = "RunThisAsService" const runAsServiceArg = "RunThisAsService"
func TestMain(m *testing.M) { 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()) 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)
} }
if len(*reportDir) == 0 {
log.Fatalf("Invalid arguments: %v", os.Args) log.Fatal("missing su.reportDir argument")
}
writeReport(*reportDir, "call")
runService()
writeReport(*reportDir, "finished")
} }
func TestInstallRunRestartStopRemove(t *testing.T) { func TestInstallRunRestartStopRemove(t *testing.T) {
@ -168,7 +170,7 @@ func mustNewRunAsService(
) service.Service { ) service.Service {
sc := &service.Config{ sc := &service.Config{
Name: "go_service_test", 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) s, err := service.New(p, sc)
if err != nil { if err != nil {

View File

@ -9,6 +9,8 @@ import (
"fmt" "fmt"
"os" "os"
"os/signal" "os/signal"
"regexp"
"strconv"
"text/template" "text/template"
"time" "time"
) )
@ -54,6 +56,47 @@ func (s *upstart) configPath() (cp string, err error) {
cp = "/etc/init/" + s.Config.Name + ".conf" cp = "/etc/init/" + s.Config.Name + ".conf"
return 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 { func (s *upstart) template() *template.Template {
return template.Must(template.New("").Funcs(tf).Parse(upstartScript)) return template.Must(template.New("").Funcs(tf).Parse(upstartScript))
} }
@ -81,10 +124,12 @@ func (s *upstart) Install() error {
var to = &struct { var to = &struct {
*Config *Config
Path string Path string
HasKillStanza bool
}{ }{
s.Config, s.Config,
path, path,
s.hasKillStanza(),
} }
return s.template().Execute(f, to) return s.template().Execute(f, to)
@ -149,7 +194,7 @@ const upstartScript = `# {{.Description}}
{{if .DisplayName}}description "{{.DisplayName}}"{{end}} {{if .DisplayName}}description "{{.DisplayName}}"{{end}}
kill signal INT {{if .HasKillStanza}}kill signal INT{{end}}
{{if .ChRoot}}chroot {{.ChRoot}}{{end}} {{if .ChRoot}}chroot {{.ChRoot}}{{end}}
{{if .WorkingDirectory}}chdir {{.WorkingDirectory}}{{end}} {{if .WorkingDirectory}}chdir {{.WorkingDirectory}}{{end}}
start on filesystem or runlevel [2345] start on filesystem or runlevel [2345]

View File

@ -41,6 +41,10 @@ var (
ErrMustRevalidateNoArgs = errors.New("Unexpected argument to `must-revalidate`") ErrMustRevalidateNoArgs = errors.New("Unexpected argument to `must-revalidate`")
ErrPublicNoArgs = errors.New("Unexpected argument to `public`") ErrPublicNoArgs = errors.New("Unexpected argument to `public`")
ErrProxyRevalidateNoArgs = errors.New("Unexpected argument to `proxy-revalidate`") 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 { func whitespace(b byte) bool {
@ -403,6 +407,21 @@ type ResponseCacheDirectives struct {
// proxy-revalidate response directive. // proxy-revalidate response directive.
SMaxAge DeltaSeconds 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 // Extensions: http://tools.ietf.org/html/rfc7234#section-5.2.3
// //
// The Cache-Control header field can be extended through the use of one // 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{ cd := &ResponseCacheDirectives{
MaxAge: -1, MaxAge: -1,
SMaxAge: -1, SMaxAge: -1,
// Exerimantal stale timeouts
StaleIfError: -1,
StaleWhileRevalidate: -1,
} }
err := parse(value, cd) err := parse(value, cd)
@ -446,6 +468,13 @@ func (cd *ResponseCacheDirectives) addToken(token string) error {
err = ErrMaxAgeDeltaSeconds err = ErrMaxAgeDeltaSeconds
case "s-maxage": case "s-maxage":
err = ErrSMaxAgeDeltaSeconds err = ErrSMaxAgeDeltaSeconds
// Experimental
case "immutable":
cd.Immutable = true
case "stale-if-error":
err = ErrMaxAgeDeltaSeconds
case "stale-while-revalidate":
err = ErrMaxAgeDeltaSeconds
default: default:
cd.Extensions = append(cd.Extensions, token) cd.Extensions = append(cd.Extensions, token)
} }
@ -500,6 +529,13 @@ func (cd *ResponseCacheDirectives) addPair(token string, v string) error {
cd.MaxAge, err = parseDeltaSeconds(v) cd.MaxAge, err = parseDeltaSeconds(v)
case "s-maxage": case "s-maxage":
cd.SMaxAge, err = parseDeltaSeconds(v) 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: default:
// TODO(pquerna): this sucks, making user re-parse, and its technically not 'quoted' like the original, // 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 "=" // 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) 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) { func TestParseDeltaSecondsZero(t *testing.T) {
ds, err := parseDeltaSeconds("0") ds, err := parseDeltaSeconds("0")
require.NoError(t, err) require.NoError(t, err)