From 3264532004563670014b7ed53c7bd65dd903933f Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 21 Oct 2016 00:12:31 +0900 Subject: [PATCH] doc: Add and use LicenseYear --- _docs/gen.go | 9 +++------ internal/license.go | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/_docs/gen.go b/_docs/gen.go index 3112bf97d..30416bb64 100644 --- a/_docs/gen.go +++ b/_docs/gen.go @@ -27,6 +27,8 @@ import ( "regexp" "strconv" "strings" + + "github.com/hajimehoshi/ebiten/internal" ) func execute(command string, args ...string) error { @@ -55,12 +57,7 @@ var ( ) func init() { - b, err := ioutil.ReadFile("../LICENSE") - if err != nil { - panic(err) - } - license := strings.TrimSpace(string(b)) - year, err := strconv.Atoi(regexp.MustCompile(`^Copyright (\d+)`).FindStringSubmatch(license)[1]) + year, err := internal.LicenseYear() if err != nil { panic(err) } diff --git a/internal/license.go b/internal/license.go index 8f36cbba6..a96b0277d 100644 --- a/internal/license.go +++ b/internal/license.go @@ -17,7 +17,9 @@ package internal import ( "io/ioutil" "path/filepath" + "regexp" "runtime" + "strconv" "strings" ) @@ -33,3 +35,15 @@ func LicenseComment() (string, error) { license := "// " + strings.Join(lines[:len(lines)-1], "\n// ") return license, nil } + +func LicenseYear() (int, error) { + license, err := LicenseComment() + if err != nil { + return 0, err + } + year, err := strconv.Atoi(regexp.MustCompile(`^// Copyright (\d+)`).FindStringSubmatch(license)[1]) + if err != nil { + return 0, err + } + return year, nil +}