├── .env.example ├── LICENSE ├── go.mod ├── go.sum ├── integration.go └── module.go /.env.example: -------------------------------------------------------------------------------- 1 | GITHUB_TOKEN=https://github.com/settings/tokens 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023 OctoLab, https://www.octolab.org/ 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module go.octolab.org/template/module 2 | 3 | go 1.11 4 | 5 | require golang.org/x/time v0.5.0 6 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= 2 | golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= 3 | -------------------------------------------------------------------------------- /integration.go: -------------------------------------------------------------------------------- 1 | package module 2 | 3 | import ( 4 | "context" 5 | "encoding/xml" 6 | "fmt" 7 | "net/http" 8 | ) 9 | 10 | // PanicOnErr panics if err is not nil. 11 | func PanicOnErr(err error) { 12 | if err != nil { 13 | panic(err) 14 | } 15 | } 16 | 17 | // Ping sends a request to the module and returns true if it's successful. 18 | func Ping(ctx context.Context, m *Module) bool { 19 | url := fmt.Sprintf("https://%s/?go-get=1", m.name) 20 | req, err := http.NewRequest(http.MethodGet, url, nil) 21 | PanicOnErr(err) 22 | // compatible with go1.11 and go1.12 23 | req = req.WithContext(ctx) 24 | 25 | resp, err := http.DefaultClient.Do(req) 26 | PanicOnErr(err) 27 | defer func() { _ = resp.Body.Close() }() 28 | 29 | var data struct { 30 | Head struct { 31 | Title string `xml:"title"` 32 | } `xml:"head"` 33 | } 34 | decoder := xml.NewDecoder(resp.Body) 35 | decoder.Strict = false 36 | decoder.AutoClose = xml.HTMLAutoClose 37 | decoder.Entity = xml.HTMLEntity 38 | PanicOnErr(decoder.Decode(&data)) 39 | return m.name == data.Head.Title 40 | } 41 | -------------------------------------------------------------------------------- /module.go: -------------------------------------------------------------------------------- 1 | // Package module provides a template for a typical module written on Go. 2 | // 3 | // It's a good starting point to build your module from scratch and 4 | // not to think about boring stuff such as ci/cd configuring and 5 | // docs publishing. 6 | // 7 | // To learn more about the module, read the docs: 8 | // 9 | // go doc -all . 10 | // 11 | // Want to know how to write Go doc comments? 12 | // Read the official [guide]. 13 | // 14 | // [guide]: https://go.dev/doc/comment. 15 | package module 16 | 17 | import "golang.org/x/time/rate" 18 | 19 | // NewModule returns a new module with [golang.org/x/time/rate.Sometimes]. 20 | // 21 | //go:generate echo Module{Limit: rate.Sometimes{once}} 22 | func NewModule() *Module { 23 | return &Module{ 24 | name: "go.octolab.org/template/module", 25 | version: "v1.0.0", 26 | } 27 | } 28 | 29 | // A Module is a stub to show how to describe a type. 30 | type Module struct { 31 | // Limit is a module rate limit. 32 | Limit rate.Sometimes 33 | 34 | name string 35 | version string // version of the module 36 | } 37 | --------------------------------------------------------------------------------