1
Fork 0

Initial commit

This commit is contained in:
Jan-Lukas Else 2022-08-09 18:18:29 +02:00
commit 8415f4a5bd
10 changed files with 217 additions and 0 deletions

16
README.md Normal file
View File

@ -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.

8
go.mod Normal file
View File

@ -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
)

4
go.sum Normal file
View File

@ -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=

33
plugin.go Normal file
View File

@ -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)
}

View File

@ -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.

View File

@ -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.

View File

@ -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
}

21
vendor/go.goblog.app/app/LICENSE vendored Normal file
View File

@ -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.

View File

@ -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
}

6
vendor/modules.txt vendored Normal file
View File

@ -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