Browse Source

Update

pull/1/head
Medzik 1 year ago
parent
commit
ba56ea0533
  1. 14
      .github/dependabot.yml
  2. 20
      .github/workflows/lint.yml
  3. 27
      .github/workflows/release.yml
  4. 4
      .gitpod.yml
  5. 22
      .goreleaser.yml
  6. 5
      go.mod
  7. 4
      go.sum
  8. 16
      imgur/client.go
  9. 16
      imgur/upload.go
  10. 42
      main.go

14
.github/dependabot.yml

@ -0,0 +1,14 @@
version: 2
updates:
# Maintain dependencies for Go modules
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "daily"
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"

20
.github/workflows/lint.yml

@ -0,0 +1,20 @@
name: lint
on:
pull_request:
push:
jobs:
golangci:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16
- name: GolangCi Lint
uses: golangci/golangci-lint-action@v2
with:
version: latest

27
.github/workflows/release.yml

@ -0,0 +1,27 @@
name: goreleaser
on:
pull_request:
push:
permissions:
contents: write
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

4
.gitpod.yml

@ -1,8 +1,8 @@
ports:
- port: 8080
checkoutLocation: "go/src/cdn"
workspaceLocation: "go/src/cdn"
checkoutLocation: "go/src/screenshot"
workspaceLocation: "go/src/screenshot"
vscode:
extensions:

22
.goreleaser.yml

@ -0,0 +1,22 @@
project_name: screenshot
before:
hooks:
- go mod tidy
builds:
- goos:
- linux
goarch:
- amd64
binary: '{{ .ProjectName }}.out'
archives:
- format: tar.gz
files:
- none*
checksum:
name_template: 'checksums.txt'

5
go.mod

@ -1,3 +1,8 @@
module gitlab.com/gaming0skar123/go/screenshot
go 1.16
require (
github.com/gtuk/discordwebhook v1.0.0
gitlab.com/gaming0skar123/go/modules/imgur v0.0.1-alpha.3
)

4
go.sum

@ -0,0 +1,4 @@
github.com/gtuk/discordwebhook v1.0.0 h1:xY21mwzScQQZeVkAPMQTB/XHIBx1lkjLeg7aALzTfOk=
github.com/gtuk/discordwebhook v1.0.0/go.mod h1:U3LdXNJ1e0bx3MMe2a4mB1VBantPHOPly2jNd8ZWXec=
gitlab.com/gaming0skar123/go/modules/imgur v0.0.1-alpha.3 h1:UKH8ZURQNfyav+cMpyjrf/WPkb7sLJiPUnezKlmQrX4=
gitlab.com/gaming0skar123/go/modules/imgur v0.0.1-alpha.3/go.mod h1:Y8l7x4FzTVYVgQXCZJOMs8H7eDzlEyxhTBhW6FEr5Bo=

16
imgur/client.go

@ -0,0 +1,16 @@
package imgur
import (
"net/http"
"os"
"gitlab.com/gaming0skar123/go/modules/imgur"
)
var client *imgur.Client
func init() {
client = new(imgur.Client)
client.HTTPClient = new(http.Client)
client.ImgurClientID = os.Getenv("IMGUR_CLIENT_ID")
}

16
imgur/upload.go

@ -0,0 +1,16 @@
package imgur
import (
"log"
"gitlab.com/gaming0skar123/go/modules/imgur"
)
func Upload(path string) *imgur.ImageInfoData {
i, _, err := client.UploadImageFromFile(path, "")
if err != nil {
log.Fatal("Error uploading image: " + err.Error())
}
return i
}

42
main.go

@ -0,0 +1,42 @@
package main
import (
"flag"
"fmt"
"log"
"os"
"github.com/gtuk/discordwebhook"
"gitlab.com/gaming0skar123/go/screenshot/imgur"
)
var color = "1127128"
func main() {
var file string
flag.StringVar(&file, "f", "", "File location")
flag.Parse()
if file == "" {
log.Fatal("Empty file arg")
}
i := imgur.Upload(file)
fmt.Println("Uploaded!")
webhook := os.Getenv("DISCORD_WEBHOOK_URL")
discordwebhook.SendMessage(webhook, discordwebhook.Message{
Embeds: &[]discordwebhook.Embed{
{
Title: &i.Data.Link,
Color: &color,
Image: &discordwebhook.Image{
Url: &i.Data.Link,
},
},
},
})
}
Loading…
Cancel
Save