Skip to content

Commit

Permalink
Merge pull request #36 from osspkg/develop
Browse files Browse the repository at this point in the history
update vendors
  • Loading branch information
markus621 committed Jan 4, 2024
2 parents a8881aa + 9a69f69 commit f991bf6
Show file tree
Hide file tree
Showing 23 changed files with 402 additions and 177 deletions.
29 changes: 29 additions & 0 deletions .deb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package: urione
source: urione
version: 1:1.3.1
architecture:
- amd64
- arm64
maintainer: The OSSPkg Team <github@osspkg.com>
homepage: https://uri.one/
description:
- Link shortening service
section: utils
priority: optional
control:
depends:
- systemd
- ca-certificates
build: devtool build --arch=%arch%
conffiles:
- /etc/urione/config.yaml
preinst: scripts/preinst.sh
postinst: scripts/postinst.sh
prerm: scripts/prerm.sh
postrm: scripts/postrm.sh
data:
bin/urione: build/urione_%arch%
etc/urione/config.yaml: config/config.yaml
var/log/urione.log: +empty
etc/systemd/system/urione.service: init/urione.service
var/lib/urione/migrations/00001.sql: migrations/00001.sql
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,6 @@ linters:
- unused
- prealloc
- durationcheck
- nolintlint
- staticcheck
- makezero
- nilerr
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2020-2023, Mikhail Knyazhev <markus621@yandex.ru>
Copyright (c) 2020-2024, Mikhail Knyazhev <markus621@yandex.ru>

**************************************************************************

Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ pre-commite: setup lint build tests
ci: install setup lint build tests

run_local:
rm -rf config/config.dev.yaml
go run cmd/uri-one/main.go --config=config/config.dev.yaml
go run cmd/urione/main.go --config=config/config.dev.yaml

deb:
deb-builder build
34 changes: 18 additions & 16 deletions app/badges/badges.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2023 Mikhail Knyazhev <markus621@yandex.ru>. All rights reserved.
* Copyright (c) 2020-2024 Mikhail Knyazhev <markus621@yandex.ru>. All rights reserved.
* Use of this source code is governed by a GPL-3.0 license that can be found in the LICENSE file.
*/

Expand All @@ -8,29 +8,31 @@ package badges
import (
"html"

"github.com/osspkg/go-badges"
"github.com/osspkg/go-sdk/app"
"github.com/osspkg/go-sdk/log"
"github.com/osspkg/goppy/plugins"
"github.com/osspkg/goppy/plugins/web"
"github.com/osspkg/uri-one/app/mainapp"
"go.osspkg.com/badges"
"go.osspkg.com/goppy/plugins"
"go.osspkg.com/goppy/web"
"go.osspkg.com/goppy/xlog"
)

var Plugin = plugins.Plugin{
Inject: New,
}

type Badge struct {
route web.Router
badge *badges.Badges
address mainapp.Address
route web.Router
badge *badges.Badges
}

func New(r web.RouterPool) *Badge {
func New(r web.RouterPool, d mainapp.Address) *Badge {
return &Badge{
route: r.Main(),
address: d,
route: r.Main(),
}
}

func (v *Badge) Up(ctx app.Context) (err error) {
func (v *Badge) Up() (err error) {
if v.badge, err = badges.New(); err != nil {
return err
}
Expand All @@ -46,7 +48,7 @@ func (v *Badge) Down() error {
}

func (v *Badge) Index(ctx web.Context) {
ctx.String(200, indexHTML)
ctx.String(200, indexHTML, string(v.address), string(v.address))
}

var colors = map[string]badges.Color{
Expand All @@ -63,7 +65,7 @@ func (v *Badge) Draw(ctx web.Context) {
title, err := ctx.Param("title").String()
if err != nil {
ctx.String(400, "Invalid `title`")
ctx.Log().WithFields(log.Fields{
ctx.Log().WithFields(xlog.Fields{
"err": err.Error(),
"key": "title",
}).Errorf("Invalid badge key")
Expand All @@ -73,7 +75,7 @@ func (v *Badge) Draw(ctx web.Context) {
data, err := ctx.Param("data").String()
if err != nil {
ctx.String(400, "Invalid `data`")
ctx.Log().WithFields(log.Fields{
ctx.Log().WithFields(xlog.Fields{
"err": err.Error(),
"key": "data",
}).Errorf("Invalid badge key")
Expand All @@ -83,7 +85,7 @@ func (v *Badge) Draw(ctx web.Context) {
color, err := ctx.Param("color").String()
if err != nil {
ctx.String(400, "Invalid `color`")
ctx.Log().WithFields(log.Fields{
ctx.Log().WithFields(xlog.Fields{
"err": err.Error(),
"key": "color",
}).Errorf("Invalid badge key")
Expand All @@ -97,7 +99,7 @@ func (v *Badge) Draw(ctx web.Context) {

err = v.badge.WriteResponse(ctx.Response(), colored, html.EscapeString(title), html.EscapeString(data))
if err != nil {
ctx.Log().WithFields(log.Fields{
ctx.Log().WithFields(xlog.Fields{
"err": err.Error(),
}).Errorf("Invalid badge response")
}
Expand Down
22 changes: 11 additions & 11 deletions app/badges/html.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2023 Mikhail Knyazhev <markus621@yandex.ru>. All rights reserved.
* Copyright (c) 2020-2024 Mikhail Knyazhev <markus621@yandex.ru>. All rights reserved.
* Use of this source code is governed by a GPL-3.0 license that can be found in the LICENSE file.
*/

Expand All @@ -12,7 +12,7 @@ const indexHTML = `
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<title>UriOne - Badge</title>
<title>Badge</title>
<style>
body {
margin: 30vh auto 0 auto;
Expand All @@ -25,7 +25,7 @@ const indexHTML = `
<body>
<h1>Badge Generation</h1>
<code>https://uri.one/badge/[color]/[title]/[data]/image.svg</code>
<code>%s/badge/[color]/[title]/[data]/image.svg</code>
<p>Color:
<span style="color: #0d6efd">primary</span>,
<span style="color: #6c757d">secondary</span>,
Expand All @@ -37,15 +37,15 @@ const indexHTML = `
</p>
<br><br>
<h1>Example</h1>
<pre>&lt;img src=&quot;https://uri.one/badge/light/User ID/12/image.svg&quot;&gt;</pre>
<pre>&lt;img src=&quot;%s/badge/light/User ID/12/image.svg&quot;&gt;</pre>
<p>
<img src="/badge/primary/User ID/12/image.svg">
<img src="/badge/secondary/User ID/12/image.svg">
<img src="/badge/success/User ID/12/image.svg">
<img src="/badge/danger/User ID/12/image.svg">
<img src="/badge/warning/User ID/12/image.svg">
<img src="/badge/info/User ID/12/image.svg">
<img src="/badge/light/User ID/12/image.svg">
<img src="/badge/primary/primary/color/image.svg">
<img src="/badge/secondary/secondary/color/image.svg">
<img src="/badge/success/success/color/image.svg">
<img src="/badge/danger/danger/color/image.svg">
<img src="/badge/warning/warning/color/image.svg">
<img src="/badge/info/info/color/image.svg">
<img src="/badge/light/light/color/image.svg">
</p>
</body>
Expand Down
9 changes: 4 additions & 5 deletions app/common/common.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/*
* Copyright (c) 2020-2023 Mikhail Knyazhev <markus621@yandex.ru>. All rights reserved.
* Copyright (c) 2020-2024 Mikhail Knyazhev <markus621@yandex.ru>. All rights reserved.
* Use of this source code is governed by a GPL-3.0 license that can be found in the LICENSE file.
*/

package common

import (
"github.com/osspkg/go-sdk/app"
"github.com/osspkg/goppy/plugins"
"github.com/osspkg/goppy/plugins/web"
"go.osspkg.com/goppy/plugins"
"go.osspkg.com/goppy/web"
)

var Plugin = plugins.Plugin{
Expand All @@ -25,7 +24,7 @@ func New(r web.RouterPool) *Shorten {
}
}

func (v *Shorten) Up(ctx app.Context) error {
func (v *Shorten) Up() error {
v.route.NotFoundHandler(v.Page404)
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions app/common/html.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2023 Mikhail Knyazhev <markus621@yandex.ru>. All rights reserved.
* Copyright (c) 2020-2024 Mikhail Knyazhev <markus621@yandex.ru>. All rights reserved.
* Use of this source code is governed by a GPL-3.0 license that can be found in the LICENSE file.
*/

Expand All @@ -12,7 +12,7 @@ const page404HTML = `
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<title>UriOne - 404</title>
<title>404</title>
<style>
body {
margin: 30vh auto 0 auto;
Expand All @@ -28,7 +28,7 @@ const page404HTML = `
</head>
<body>
<h1 class="number">404</h1>
<h1>Page not found</h1>
<h1>Not found</h1>
</body>
</html>
`
17 changes: 17 additions & 0 deletions app/mainapp/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) 2020-2024 Mikhail Knyazhev <markus621@yandex.ru>. All rights reserved.
* Use of this source code is governed by a GPL-3.0 license that can be found in the LICENSE file.
*/

package mainapp

import "go.osspkg.com/goppy/plugins"

type Address string

var Plugin = plugins.Plugin{
Config: &Config{},
Inject: func(c *Config) Address {
return Address(c.Address)
},
}
14 changes: 14 additions & 0 deletions app/mainapp/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (c) 2020-2024 Mikhail Knyazhev <markus621@yandex.ru>. All rights reserved.
* Use of this source code is governed by a GPL-3.0 license that can be found in the LICENSE file.
*/

package mainapp

type Config struct {
Address string `yaml:"address"`
}

func (v *Config) Default() {
v.Address = "http://localhost:8080"
}
2 changes: 1 addition & 1 deletion app/shorten/config.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2023 Mikhail Knyazhev <markus621@yandex.ru>. All rights reserved.
* Copyright (c) 2020-2024 Mikhail Knyazhev <markus621@yandex.ru>. All rights reserved.
* Use of this source code is governed by a GPL-3.0 license that can be found in the LICENSE file.
*/

Expand Down
6 changes: 3 additions & 3 deletions app/shorten/html.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2023 Mikhail Knyazhev <markus621@yandex.ru>. All rights reserved.
* Copyright (c) 2020-2024 Mikhail Knyazhev <markus621@yandex.ru>. All rights reserved.
* Use of this source code is governed by a GPL-3.0 license that can be found in the LICENSE file.
*/

Expand All @@ -12,7 +12,7 @@ const page404HTML = `
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<title>UriOne - 404</title>
<title>404</title>
<style>
body {
margin: 30vh auto 0 auto;
Expand All @@ -28,7 +28,7 @@ const page404HTML = `
</head>
<body>
<h1 class="number">404</h1>
<h1>Link not found</h1>
<h1>Not found</h1>
</body>
</html>
`
Loading

0 comments on commit f991bf6

Please sign in to comment.