Compare commits

...

16 Commits
v1.0.0 ... main

Author SHA1 Message Date
dependabot[bot] c46cac3be8
Bump go.mongodb.org/mongo-driver from 1.7.1 to 1.7.2 (#10)
Bumps [go.mongodb.org/mongo-driver](https://github.com/mongodb/mongo-go-driver) from 1.7.1 to 1.7.2.
- [Release notes](https://github.com/mongodb/mongo-go-driver/releases)
- [Commits](https://github.com/mongodb/mongo-go-driver/compare/v1.7.1...v1.7.2)

---
updated-dependencies:
- dependency-name: go.mongodb.org/mongo-driver
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-10-24 14:01:21 +02:00
dependabot[bot] 277af280f1
Bump github.com/andersfylling/disgord from 0.28.3 to 0.29.0 (#9)
Bumps [github.com/andersfylling/disgord](https://github.com/andersfylling/disgord) from 0.28.3 to 0.29.0.
- [Release notes](https://github.com/andersfylling/disgord/releases)
- [Commits](https://github.com/andersfylling/disgord/compare/v0.28.3...v0.29.0)

---
updated-dependencies:
- dependency-name: github.com/andersfylling/disgord
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-10-24 14:01:06 +02:00
MedzikUser f67a0c0e8c
Merge pull request #5 from MedzikUser/dependabot/go_modules/go.mongodb.org/mongo-driver-1.7.1
Bump go.mongodb.org/mongo-driver from 1.7.0 to 1.7.1
2021-08-16 21:53:46 +02:00
MedzikUser ccab8d6482
Merge pull request #7 from MedzikUser/dependabot/go_modules/github.com/andersfylling/disgord-0.28.3
Bump github.com/andersfylling/disgord from 0.27.3 to 0.28.3
2021-08-16 21:53:29 +02:00
MedzikUser 6080d3274c
Merge pull request #8 from MedzikUser/dependabot/go_modules/github.com/gin-gonic/gin-1.7.4
Bump github.com/gin-gonic/gin from 1.7.2 to 1.7.4
2021-08-16 21:53:16 +02:00
dependabot[bot] 7123ce9c84
Bump github.com/gin-gonic/gin from 1.7.2 to 1.7.4
Bumps [github.com/gin-gonic/gin](https://github.com/gin-gonic/gin) from 1.7.2 to 1.7.4.
- [Release notes](https://github.com/gin-gonic/gin/releases)
- [Changelog](https://github.com/gin-gonic/gin/blob/master/CHANGELOG.md)
- [Commits](https://github.com/gin-gonic/gin/compare/v1.7.2...v1.7.4)

---
updated-dependencies:
- dependency-name: github.com/gin-gonic/gin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-16 14:20:57 +00:00
dependabot[bot] 261335f905
Bump github.com/andersfylling/disgord from 0.27.3 to 0.28.3
Bumps [github.com/andersfylling/disgord](https://github.com/andersfylling/disgord) from 0.27.3 to 0.28.3.
- [Release notes](https://github.com/andersfylling/disgord/releases)
- [Commits](https://github.com/andersfylling/disgord/compare/v0.27.3...v0.28.3)

---
updated-dependencies:
- dependency-name: github.com/andersfylling/disgord
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-09 14:17:15 +00:00
dependabot[bot] 1028b74953
Bump go.mongodb.org/mongo-driver from 1.7.0 to 1.7.1
Bumps [go.mongodb.org/mongo-driver](https://github.com/mongodb/mongo-go-driver) from 1.7.0 to 1.7.1.
- [Release notes](https://github.com/mongodb/mongo-go-driver/releases)
- [Commits](https://github.com/mongodb/mongo-go-driver/compare/v1.7.0...v1.7.1)

---
updated-dependencies:
- dependency-name: go.mongodb.org/mongo-driver
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-04 14:28:13 +00:00
MedzikUser 63811dc8ee
Merge pull request #3 from MedzikUser/dependabot/go_modules/github.com/andersfylling/disgord-0.27.3
Bump github.com/andersfylling/disgord from 0.27.2 to 0.27.3
2021-07-27 10:41:38 +02:00
dependabot[bot] fede3de7a4
Bump github.com/andersfylling/disgord from 0.27.2 to 0.27.3
Bumps [github.com/andersfylling/disgord](https://github.com/andersfylling/disgord) from 0.27.2 to 0.27.3.
- [Release notes](https://github.com/andersfylling/disgord/releases)
- [Commits](https://github.com/andersfylling/disgord/compare/v0.27.2...v0.27.3)

---
updated-dependencies:
- dependency-name: github.com/andersfylling/disgord
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-07-26 14:17:58 +00:00
MedzikUser 5c7f6c4b87
Merge pull request #1 from MedzikUser/dependabot/go_modules/go.mongodb.org/mongo-driver-1.7.0
Bump go.mongodb.org/mongo-driver from 1.6.0 to 1.7.0
2021-07-21 20:43:57 +02:00
dependabot[bot] 4c9c456ed3
Bump go.mongodb.org/mongo-driver from 1.6.0 to 1.7.0
Bumps [go.mongodb.org/mongo-driver](https://github.com/mongodb/mongo-go-driver) from 1.6.0 to 1.7.0.
- [Release notes](https://github.com/mongodb/mongo-go-driver/releases)
- [Commits](https://github.com/mongodb/mongo-go-driver/compare/v1.6.0...v1.7.0)

---
updated-dependencies:
- dependency-name: go.mongodb.org/mongo-driver
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-07-21 14:16:19 +00:00
Medzik 36ea49e9ac discord: Fixed watch channels 2021-07-16 18:03:24 +02:00
Medzik 87c7dc4f8f Added YML config and More
- Discord Bot: Added YML config and moved bot settings from DB to this file
- Error logs names has been renames
- Discord Bot: Added upload from multi attachments
- Update README, Makefile, go.mod and .gitignore
2021-07-15 14:33:17 +02:00
Medzik b30d28ac0e Fixed lint error 2021-07-15 11:54:03 +02:00
Medzik 87933a3f92 Fixed one lint error 2021-07-15 11:38:56 +02:00
17 changed files with 144 additions and 155 deletions

12
.gitignore vendored
View File

@ -12,13 +12,9 @@
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
# Output
*.out
cdn*
# Sums
MD5SUM
SHA256SUM
VERSION
dist/
# Config
config.yml

View File

@ -6,9 +6,6 @@ build:
run:
go run .
deps:
go get -v
clean:
go clean
rm cdn* dist
rm ${OUT_FILE} dist

View File

@ -1,13 +1,13 @@
# Image CDN - API and Discord Bot
![Pipeline Badge](https://gitlab.com/gaming0skar123/go/cdn/badges/main/pipeline.svg)
## Install Pre-Compile binary
* Linux
* Downoad `curl -L https://gitlab.com/gaming0skar123/go/cdn/-/jobs/artifacts/main/raw/cdn-linux-amd64?job=build --output cdn`
* Add permissions `chmod +rwx cdn`
* Run binary `./cdn`
* Linux amd64
* [Download](https://github.com/MedzikUser/go-cdn/releases) latest version
* Unpack file `tar xzf cdn_{VERSION}_linux_amd64.tar.gz`
* Create an .env and config.yml file and complete according to .env.schema and config.schema.yml
* Add permissions `chmod +rwx cdn.out`
* Run binary `./cdn.out`
## Disable Automatic Updates

5
config.schema.yml Normal file
View File

@ -0,0 +1,5 @@
discord:
api_channel: 234567890123456789
channels:
- 123456789012345678
- 987654321098765433

View File

@ -4,5 +4,5 @@ import (
"time"
)
var GH_Repo = "MagicJuszer/go-cdn"
var GH_Repo = "MedzikUser/go-cdn"
var Latest_Version_Check = 2 * time.Minute

View File

@ -1,3 +1,3 @@
package config
var Version = "1.0.0"
var Version = "1.1.1"

36
config/yml.go Normal file
View File

@ -0,0 +1,36 @@
package config
import (
"io/ioutil"
"gitlab.com/gaming0skar123/go/cdn/common"
"gopkg.in/yaml.v2"
)
type YmlConfig struct {
Discord YmlConfigDiscord
}
type YmlConfigDiscord struct {
API_Channel string
Channels []string
}
var API_Channel string
var Channels []string
func init() {
f, err := ioutil.ReadFile("config.yml")
if common.CheckErr(err, "read config file") {
return
}
var data YmlConfig
err = yaml.Unmarshal(f, &data)
if common.CheckErr(err, "unmarshal config file") {
return
}
API_Channel = data.Discord.API_Channel
Channels = data.Discord.Channels
}

View File

@ -1,61 +0,0 @@
package database
import (
"context"
"time"
"gitlab.com/gaming0skar123/go/cdn/common"
"gitlab.com/gaming0skar123/go/cdn/config"
"go.mongodb.org/mongo-driver/bson"
)
type Channel struct {
ID string `bson:"_id"`
GuildID string `bson:"gid"`
}
type ChannelAPI struct {
ID string `bson:"_id"`
}
func InsertChannel(channel *Channel) {
collection := DB.Collection(config.Mongo_Collection_Channel)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
_, err := collection.InsertOne(ctx, channel)
common.CheckErr(err, "inserting to DB")
}
func InsertAPIChannel(channel *ChannelAPI) {
collection := DB.Collection(config.Mongo_Collection_Channel_API)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
_, err := collection.InsertOne(ctx, channel)
common.CheckErr(err, "inserting to DB")
}
func FindChannel(channel *Channel) bool {
collection := DB.Collection(config.Mongo_Collection_Channel)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
err := collection.FindOne(ctx, channel).Decode(&channel)
return err == nil
}
func FindAPIChannel() (*ChannelAPI, error) {
collection := DB.Collection(config.Mongo_Collection_Channel_API)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
var channel *ChannelAPI
err := collection.FindOne(ctx, bson.D{}).Decode(&channel)
return channel, err
}

View File

@ -7,7 +7,6 @@ import (
"github.com/andersfylling/snowflake/v5"
"gitlab.com/gaming0skar123/go/cdn/common"
"gitlab.com/gaming0skar123/go/cdn/config"
"gitlab.com/gaming0skar123/go/cdn/database"
)
var c *disgord.Client
@ -17,17 +16,12 @@ func apiInit(client *disgord.Client) {
}
func API(link string) {
channel, err := database.FindAPIChannel()
if common.CheckErr(err, "FindAPIChannel()") {
s, err := snowflake.GetSnowflake(config.API_Channel)
if common.CheckErr(err, "get snowflake") {
return
}
s, err := snowflake.GetSnowflake(channel.ID)
if common.CheckErr(err, "GetSnowflake("+channel.ID+")") {
return
}
c.SendMsg(s, disgord.Embed{
_, err = c.SendMsg(s, disgord.Embed{
Title: link,
Timestamp: disgord.Time{
Time: time.Now().UTC(),
@ -37,4 +31,8 @@ func API(link string) {
URL: link,
},
})
if common.CheckErr(err, "send msg") {
return
}
}

View File

@ -29,7 +29,10 @@ func Bot() {
// DMIntents: disgord.IntentDirectMessages | disgord.IntentDirectMessageReactions | disgord.IntentDirectMessageTyping,
})
defer client.Gateway().StayConnectedUntilInterrupted()
defer func() {
err := client.Gateway().StayConnectedUntilInterrupted()
common.CheckErr(err, "stay bot connection")
}()
filter, _ := std.NewMsgFilter(ctx, client)

View File

@ -11,6 +11,6 @@ func deleteMsg(s disgord.Session, m *disgord.Message, t time.Duration) {
go func() {
time.Sleep(t)
err := s.Channel(m.ChannelID).Message(m.ID).Delete()
common.CheckErr(err, "delete message")
common.CheckErr(err, "delete msg")
}()
}

View File

@ -6,69 +6,35 @@ import (
"github.com/andersfylling/disgord"
"gitlab.com/gaming0skar123/go/cdn/common"
"gitlab.com/gaming0skar123/go/cdn/config"
"gitlab.com/gaming0skar123/go/cdn/database"
"gitlab.com/gaming0skar123/go/cdn/imgur"
)
func findChannel(channel string) bool {
for _, c := range config.Channels {
if c == channel {
return true
}
}
return false
}
func handleMsg(s disgord.Session, data *disgord.MessageCreate) {
m := data.Message
findVaue := &database.Channel{
ID: m.ChannelID.String(),
GuildID: m.GuildID.String(),
}
if !database.FindChannel(findVaue) {
if !findChannel(m.ChannelID.String()) {
return
}
err := s.Channel(m.ChannelID).TriggerTypingIndicator()
common.CheckErr(err, "TriggerTypingIndicator()")
avatarUrl, _ := m.Author.AvatarURL(64, true)
var url string
common.CheckErr(err, "trigger typing")
if len(m.Attachments) > 0 {
url = m.Attachments[0].URL
} else {
url = m.Content
}
i, err := imgur.UploadFromURL(url)
if common.CheckErr(err, "UploadFromURL("+url+")") {
mBot, err := m.Reply(ctx, s, disgord.Embed{
Title: "Error",
Description: err.Error(),
Timestamp: m.Timestamp,
Color: config.Embed_Color,
Footer: &disgord.EmbedFooter{
Text: m.Author.Tag(),
IconURL: avatarUrl,
},
})
if !common.CheckErr(err, "send message") {
deleteMsg(s, mBot, 5*time.Second)
for _, a := range m.Attachments {
uploadImg(s, m, a.URL)
}
deleteMsg(s, m, 3*time.Second)
return
} else {
uploadImg(s, m, m.Content)
}
_, err = m.Reply(ctx, s, disgord.Embed{
Title: i.Link,
Timestamp: m.Timestamp,
Color: config.Embed_Color,
Footer: &disgord.EmbedFooter{
Text: m.Author.Tag(),
IconURL: avatarUrl,
},
Image: &disgord.EmbedImage{
URL: i.Link,
},
})
common.CheckErr(err, "send message")
deleteMsg(s, m, 2*time.Second)
}

49
discord/uploadImg.go Normal file
View File

@ -0,0 +1,49 @@
package discord
import (
"time"
"github.com/andersfylling/disgord"
"gitlab.com/gaming0skar123/go/cdn/common"
"gitlab.com/gaming0skar123/go/cdn/config"
"gitlab.com/gaming0skar123/go/cdn/imgur"
)
func uploadImg(s disgord.Session, m *disgord.Message, url string) {
avatarUrl, _ := m.Author.AvatarURL(64, true)
i, err := imgur.UploadFromURL(url)
if common.CheckErr(err, "upload img") {
mBot, err := m.Reply(ctx, s, disgord.Embed{
Title: "Error",
Description: err.Error(),
Timestamp: m.Timestamp,
Color: config.Embed_Color,
Footer: &disgord.EmbedFooter{
Text: m.Author.Tag(),
IconURL: avatarUrl,
},
})
if !common.CheckErr(err, "send msg") {
deleteMsg(s, mBot, 5*time.Second)
}
deleteMsg(s, m, 3*time.Second)
return
}
_, err = m.Reply(ctx, s, disgord.Embed{
Title: i.Link,
Timestamp: m.Timestamp,
Color: config.Embed_Color,
Footer: &disgord.EmbedFooter{
Text: m.Author.Tag(),
IconURL: avatarUrl,
},
Image: &disgord.EmbedImage{
URL: i.Link,
},
})
common.CheckErr(err, "send msg")
}

8
go.mod
View File

@ -3,10 +3,10 @@ module gitlab.com/gaming0skar123/go/cdn
go 1.16
require (
github.com/andersfylling/disgord v0.27.2
github.com/andersfylling/disgord v0.29.0
github.com/andersfylling/snowflake/v5 v5.0.1
github.com/blang/semver v3.5.1+incompatible
github.com/gin-gonic/gin v1.7.2
github.com/gin-gonic/gin v1.7.4
github.com/go-playground/validator/v10 v10.7.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
@ -27,11 +27,11 @@ require (
github.com/ulikunitz/xz v0.5.10 // indirect
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
gitlab.com/gaming0skar123/go/modules/imgur v0.0.1-alpha.3
go.mongodb.org/mongo-driver v1.6.0
go.mongodb.org/mongo-driver v1.7.2
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 // indirect
golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 // indirect
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v2 v2.4.0
)

12
go.sum
View File

@ -33,8 +33,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/andersfylling/disgord v0.27.2 h1:0RJ01Fs33gyf3Lny4q6ORxbYvYM6HyD1b6d19XQ6sLs=
github.com/andersfylling/disgord v0.27.2/go.mod h1:xVShFExKzAKn/jtFdGPanouNsJ8FEe02vo+2nv78YRc=
github.com/andersfylling/disgord v0.29.0 h1:nAFeDGaiLiUd4hj2ghOdVTYAJ9nLV5acNNBa+DCl5sI=
github.com/andersfylling/disgord v0.29.0/go.mod h1:xVShFExKzAKn/jtFdGPanouNsJ8FEe02vo+2nv78YRc=
github.com/andersfylling/snowflake/v5 v5.0.1 h1:unXbYSij6tRCGJzoLz9zl3nJsqd9hu7bbYSgB8K8/i0=
github.com/andersfylling/snowflake/v5 v5.0.1/go.mod h1:AdhrB+kewjnQInv8cR7ABe2SGoVXh79njnipUnz1HFc=
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
@ -56,8 +56,8 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
github.com/gin-gonic/gin v1.7.2 h1:Tg03T9yM2xa8j6I3Z3oqLaQRSmKvxPd6g/2HJ6zICFA=
github.com/gin-gonic/gin v1.7.2/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY=
github.com/gin-gonic/gin v1.7.4 h1:QmUZXrvJ9qZ3GfWvQ+2wnW/1ePrTEJqPKMYEU3lD/DM=
github.com/gin-gonic/gin v1.7.4/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
@ -282,8 +282,8 @@ github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
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=
go.mongodb.org/mongo-driver v1.6.0 h1:ccc26ylcoRWJQRbjU7GvqfxNzwKcoIcEL3BPuFR/pJ0=
go.mongodb.org/mongo-driver v1.6.0/go.mod h1:Q4oFMbo1+MSNqICAdYMlC/zSTrwCogR4R8NzkI+yfU8=
go.mongodb.org/mongo-driver v1.7.2 h1:pFttQyIiJUHEn50YfZgC9ECjITMT44oiN36uArf/OFg=
go.mongodb.org/mongo-driver v1.7.2/go.mod h1:Q4oFMbo1+MSNqICAdYMlC/zSTrwCogR4R8NzkI+yfU8=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=

View File

@ -15,7 +15,7 @@ func Update() {
repo := config.GH_Repo
latest, found, err := selfupdate.DetectLatest(repo)
if common.CheckErr(err, "detecting letest version") {
if common.CheckErr(err, "detect latest version") {
return
}

View File

@ -23,13 +23,13 @@ func Upload(c *gin.Context) {
}
file, err := c.FormFile("file")
if common.CheckErr(err, "error form file") {
if common.CheckErr(err, "form file") {
c.String(http.StatusBadRequest, "Error Form File")
return
}
f, err := file.Open()
if common.CheckErr(err, "error opening file") {
if common.CheckErr(err, "open file") {
c.String(http.StatusBadRequest, "Error Opening File")
return
}