This is a simple library which can be used to create your own custom Golang upload handler for your ShareX client. It is based on the http mux library which I really do recommend for working with http handlers in Golang.
In ShareX you can choose between a bunch of different default built-in upload servers - but according to my expirience it was nearly impossible to manage all my uploaded files. Thats why I decided to write my own upload server (library). I chose Golang because it is a young and really powerful programming language which in my opinion has much potencial.
I will not write an own Wiki for this repository because in my opinion the usage is really simple and by explaining you some examples you should be able to use the code.
The complete code is based on interfaces which can be used to code an own implementation. Moreover you can customize all paths/uris which should be used to handle processes. If thats still not enough you can just edit the code directly because of the really flexible MIT license.
The tutorial for itself only contains a basic example which is explained with comments. The complete design code (interfaces, basic methods/structs) is commented so that you can find your way through the code.
package main
import (
"github.com/michivip/sharexhandler"
"net/http"
"github.com/gorilla/mux"
"crypto/tls"
"strings"
"log"
"os"
"github.com/michivip/sharexhandler/storages"
"gopkg.in/mgo.v2"
"bufio"
)
func main() {
log.Println("Initializing storage...")
fileFolder := "files/" // The folder where our uploaded files will be stored at.
if err := os.Mkdir(fileFolder, os.ModePerm); err != nil { // Creating the folder
panic(err)
} else {
// This example goes with the default built-in implemented MongoStorage but in your case you can use a different one.
storage := &storages.MongoStorage{
DialInfo: &mgo.DialInfo{ // The dial info. More information: https://godoc.org/labix.org/v2/mgo#DialInfo
Addrs: []string{"localhost"},
},
Configuration: &storages.MongoStorageConfiguration{ // MongoDB configuration
DatabaseName: "sharex", // Database name where collections are created in.
UploadCollectionName: "uploads", // Collection where the upload file information (not the file data) is stored at.
FileFolderPath: fileFolder, // The folder where the file data is stored at - no information.
},
}
if err := storage.Initialize(); err != nil { // Initializing the storage - in our case connecting to the database.
panic(err)
} else {
log.Println("Initialized!")
log.Println("Set up custom upload server. Running it in background...")
srv := setupHttpsServer(storage)
go srv.ListenAndServeTLS("cert.pem", "private.pem") // Our cert file and our key file which are laying in our directory.
// Now just a stop hook - nothing special.
log.Println("Done! Enter \"stop\" to stop the webservers.")
reader := bufio.NewReader(os.Stdin)
var text string
for ; strings.TrimSuffix(text, "\n") != "stop"; text, _ =