commit 8415f4a5bdfd1eed97e91a217a9b48026d33daee Author: Jan-Lukas Else Date: Tue Aug 9 18:18:29 2022 +0200 Initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..e3e8b3b --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# Demo GoBlog plugin + +This is an example GoBlog plugin with additional dependencies in a vendor directory. + +Copy this repos content to your GoBlog working directory to `plugins/advanced/src/goblog/plugin`. + +Configure the plugin: + +```yaml +plugins: + - path: ./plugins/advanced + type: exec + import: goblog/plugin +``` + +Start GoBlog. \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..2c16f51 --- /dev/null +++ b/go.mod @@ -0,0 +1,8 @@ +module goblog.plugin + +go 1.19 + +require ( + git.jlel.se/jlelse/go-geouri v0.0.0-20210525190615-a9c1d50f42d6 + go.goblog.app/app v0.0.0-20220809154753-2158b156c55b +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..18c0cf3 --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +git.jlel.se/jlelse/go-geouri v0.0.0-20210525190615-a9c1d50f42d6 h1:d7k1NKd9fr+Eq7EtUrqUly+HDqDzpx9T9v8Gl2jJvpo= +git.jlel.se/jlelse/go-geouri v0.0.0-20210525190615-a9c1d50f42d6/go.mod h1:eKL81ZHiGWZ4cdv9MI0ADmPiG9p0C+ajkSldNTr2ftQ= +go.goblog.app/app v0.0.0-20220809154753-2158b156c55b h1:v7Y60oTlQFL1UUk08PNVYH5ViMUSF+QDq2R5e1byCbM= +go.goblog.app/app v0.0.0-20220809154753-2158b156c55b/go.mod h1:kunTVTA7cLD7O24GD4UfQMFngM9OREgfKr55E7rQwPA= diff --git a/plugin.go b/plugin.go new file mode 100644 index 0000000..564fcf9 --- /dev/null +++ b/plugin.go @@ -0,0 +1,33 @@ +package plugin + +import ( + "fmt" + + gogeouri "git.jlel.se/jlelse/go-geouri" + "go.goblog.app/app/pkgs/plugintypes" +) + +func GetPlugin() plugintypes.Exec { + return &plugin{} +} + +type plugin struct { +} + +func (p *plugin) SetApp(_ plugintypes.App) { + // Ignore +} + +func (*plugin) SetConfig(_ map[string]any) { + // Ignore +} + +func (p *plugin) Exec() { + g, err := gogeouri.Parse("geo:37.786971,-122.399677") + if err != nil { + fmt.Println(err.Error()) + return + } + fmt.Println("Lon: ", g.Longitude) + fmt.Println("Lat: ", g.Latitude) +} diff --git a/vendor/git.jlel.se/jlelse/go-geouri/LICENSE b/vendor/git.jlel.se/jlelse/go-geouri/LICENSE new file mode 100644 index 0000000..73a5796 --- /dev/null +++ b/vendor/git.jlel.se/jlelse/go-geouri/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2021 Jan-Lukas Else + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/git.jlel.se/jlelse/go-geouri/README.md b/vendor/git.jlel.se/jlelse/go-geouri/README.md new file mode 100644 index 0000000..02b74c9 --- /dev/null +++ b/vendor/git.jlel.se/jlelse/go-geouri/README.md @@ -0,0 +1,7 @@ +# go-geouri + +Parse geo URI (RFC 5870) with Go + +https://datatracker.ietf.org/doc/html/rfc5870 + +Just the basics so far, doesn't check all the rules yet. \ No newline at end of file diff --git a/vendor/git.jlel.se/jlelse/go-geouri/geouri.go b/vendor/git.jlel.se/jlelse/go-geouri/geouri.go new file mode 100644 index 0000000..d4ed7cd --- /dev/null +++ b/vendor/git.jlel.se/jlelse/go-geouri/geouri.go @@ -0,0 +1,62 @@ +package gogeouri + +import ( + "errors" + "strconv" + "strings" +) + +type Geo struct { + Latitude, Longitude, Altitude float64 + Parameters map[string][]string +} + +const scheme = "geo" + +func Parse(uri string) (*Geo, error) { + g := &Geo{ + Parameters: map[string][]string{}, + } + if !strings.HasPrefix(uri, scheme+":") { + return nil, errors.New("no or wrong scheme") + } + uri = strings.TrimPrefix(uri, scheme+":") + uriParts := strings.Split(uri, ";") + if len(strings.TrimSpace(uriParts[0])) < 1 { + return nil, errors.New("empty path") + } + coords := strings.Split(uriParts[0], ",") + if l := len(coords); l < 2 || l > 3 { + return nil, errors.New("wrong number of coordinates") + } + if f, e := strconv.ParseFloat(coords[0], 64); e == nil { + g.Latitude = f + } else { + return nil, errors.New("can't parse latitude") + } + if f, e := strconv.ParseFloat(coords[1], 64); e == nil { + g.Longitude = f + } else { + return nil, errors.New("can't parse longitude") + } + if len(coords) == 3 { + if f, e := strconv.ParseFloat(coords[2], 64); e == nil { + g.Altitude = f + } else { + return nil, errors.New("can't parse altitude") + } + } + for _, p := range uriParts[1:] { + pParts := strings.Split(p, "=") + if l := len(pParts); l == 1 { + if _, ok := g.Parameters[pParts[0]]; !ok { + g.Parameters[pParts[0]] = []string{} + } + } else if l == 2 { + g.Parameters[pParts[0]] = append(g.Parameters[pParts[0]], pParts[1]) + } else { + return nil, errors.New("wrong parameter") + } + } + return g, nil +} diff --git a/vendor/go.goblog.app/app/LICENSE b/vendor/go.goblog.app/app/LICENSE new file mode 100644 index 0000000..0219d81 --- /dev/null +++ b/vendor/go.goblog.app/app/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 - 2022 Jan-Lukas Else + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/go.goblog.app/app/pkgs/plugintypes/types.go b/vendor/go.goblog.app/app/pkgs/plugintypes/types.go new file mode 100644 index 0000000..0e51fea --- /dev/null +++ b/vendor/go.goblog.app/app/pkgs/plugintypes/types.go @@ -0,0 +1,51 @@ +package plugintypes + +import ( + "context" + "database/sql" + "net/http" +) + +// Interface to GoBlog + +// App is used to access GoBlog's app instance. +type App interface { + GetDatabase() Database +} + +// Database is used to provide access to GoBlog's database. +type Database interface { + Exec(string, ...any) (sql.Result, error) + ExecContext(context.Context, string, ...any) (sql.Result, error) + Query(string, ...any) (*sql.Rows, error) + QueryContext(context.Context, string, ...any) (*sql.Rows, error) + QueryRow(string, ...any) (*sql.Row, error) + QueryRowContext(context.Context, string, ...any) (*sql.Row, error) +} + +// Plugin types + +// SetApp is used in all plugin types to allow +// GoBlog set it's app instance to be accessible by the plugin. +type SetApp interface { + SetApp(App) +} + +// SetConfig is used in all plugin types to allow +// GoBlog set plugin configuration. +type SetConfig interface { + SetConfig(map[string]any) +} + +type Exec interface { + SetApp + SetConfig + Exec() +} + +type Middleware interface { + SetApp + SetConfig + Handler(http.Handler) http.Handler + Prio() int +} diff --git a/vendor/modules.txt b/vendor/modules.txt new file mode 100644 index 0000000..91d94fc --- /dev/null +++ b/vendor/modules.txt @@ -0,0 +1,6 @@ +# git.jlel.se/jlelse/go-geouri v0.0.0-20210525190615-a9c1d50f42d6 +## explicit; go 1.16 +git.jlel.se/jlelse/go-geouri +# go.goblog.app/app v0.0.0-20220809154753-2158b156c55b +## explicit; go 1.19 +go.goblog.app/app/pkgs/plugintypes