Skip to content

Instantly share code, notes, and snippets.

@dekokun
Last active October 24, 2017 04:14
Show Gist options
  • Save dekokun/7da6caf00658f2a184352112db9bcc18 to your computer and use it in GitHub Desktop.
Save dekokun/7da6caf00658f2a184352112db9bcc18 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"github.com/marcw/cachecontrol"
"strings"
)
func main() {
ccs := []string{"public", "max-age=315360000"}
directive := strings.Join(ccs, " ")
cc := cachecontrol.Parse(directive)
fmt.Println("# publicが先だとpublic扱いにならない")
fmt.Println(ccs)
fmt.Println(cc.Public())
ccs2 := []string{"max-age=315360000", "public"}
directive2 := strings.Join(ccs, " ")
cc2 := cachecontrol.Parse(directive2)
fmt.Println("# publicが後だとpublic扱いになる")
fmt.Println(ccs2)
fmt.Println(cc2.Public())
ccs3 := []string{"public", "max-age=315360000"}
directive3 := strings.Join(ccs, " ")
cc3 := cachecontrol.Parse(directive3)
fmt.Println("# publicが先でもカンマでJoinするとpublic扱いになる")
fmt.Println(ccs3)
fmt.Println(cc3.Public())
}
@dekokun
Copy link
Author

dekokun commented Oct 24, 2017

結果:

$ go run test.go
# publicが先だとpublic扱いにならない
[public max-age=315360000]
false
# publicが後だとpublic扱いになる
[max-age=315360000 public]
false
# publicが先でもカンマでJoinするとpublic扱いになる
[public max-age=315360000]
false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment