{"id":18023611,"url":"https://github.com/jeffotoni/goupload","last_synced_at":"2026-04-29T17:32:36.292Z","repository":{"id":134047372,"uuid":"86834106","full_name":"jeffotoni/goupload","owner":"jeffotoni","description":"Simple restful server written in Go (golang) to receive uploads, we use boltdb a no-sql native go and using token with authentication.","archived":false,"fork":false,"pushed_at":"2017-04-17T16:59:15.000Z","size":2579,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-10T03:29:16.880Z","etag":null,"topics":["boltdb","docker","go","golang","receive-uploads","restful","restfulservice","sql-database-boltdb"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jeffotoni.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-03-31T15:30:16.000Z","updated_at":"2018-12-22T12:23:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"2da08833-f158-4464-9956-e36bbf44c45e","html_url":"https://github.com/jeffotoni/goupload","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffotoni%2Fgoupload","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffotoni%2Fgoupload/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffotoni%2Fgoupload/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffotoni%2Fgoupload/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jeffotoni","download_url":"https://codeload.github.com/jeffotoni/goupload/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247226280,"owners_count":20904480,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["boltdb","docker","go","golang","receive-uploads","restful","restfulservice","sql-database-boltdb"],"created_at":"2024-10-30T07:10:00.759Z","updated_at":"2026-04-29T17:32:36.262Z","avatar_url":"https://github.com/jeffotoni.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# goupload\nRestful simple server written in Go (golang) to receive uploads, we use boltdb a native-non-sql go and using token with authentication.\nYou can send client-encrypted files and common files.\nIf you prefer dockerfile available so you can build in your image and run the goupload.\n\n## Used libraries:\n- https://github.com/boltdb/bolt - No-sql native go(golang)\n- https://github.com/gorilla/mux - Implements a request router and dispatcher for matching incoming requests\n- https://github.com/fatih/color - Help define the colors in the terminal\n\n---\n* [A small summary](#summary)\n* [Docker](#docker)\n* [Clone](#clone)\n* [Get dependencies](#dependencies)\n* [Run](#runprogram)\n* [Logs Server](#rlogsserver)\n* [Build](#Build)\n* [Install](#install)\n* [Body function](#body-function)\n* [Examples Client](#examples-client)\n* [Upload File](#upload-files)\n\n## A small summary \n\n[goupload.go]\n\nA simple restful server to receive common and encrypted files will store the file on the server.\nYou will use port 8080 for communication with your api, will be written a no-sql database boltdb all \nuploads made on the server, will be generated a log on disk of all accesses.\n\n\n## Docker \n\ndocker [`Installing`] (Docker https://docs.docker.com/engine/installation)\n\n\n## Clone this repo into your GOPATH\n\n```\ngit clone https://github.com/jeffotoni/goupload\n```\n\ndockerfile-golang\n```\nFROM jeffotoni/golang\nMAINTAINER Jefferson Otoni Lima \u003cjeff.otoni@gmail.com\u003e\nADD . /go/src/github.com/jeffotoni/goupload\nRUN go install github.com/jeffotoni/goupload\nRUN mkdir -p /go/goupload\nWORKDIR /go/goupload\nENTRYPOINT /go/bin/goupload start\nEXPOSE 8080\n```\n\nBuilding image\n```\n# docker build -f dockerfile-golang -t jeffotoni/goupload:v1 .\n\n```\n\nStart image and creating container\n```\n# docker run -it --rm --name goupload-run -p 8080:8080 -v /yourpath/docker:/go/goupload  jeffotoni/goupload:v1\n\n```\n\nThere is another possibility, which is of the pull in a complete image\n\nPull in the image\n```\n# docker pull jeffotoni/golang-goupload\n\n```\n\nStart image and creating container\n```\n# docker run -it --rm --name goupload-run -p 8080:8080 -v /yourpath/docker:/go/goupload  jeffotoni/golang-goupload:v1\n\n```\n\nNow is to test and see if everything is ok\n\nSending a file to the server\n```\n# curl -X POST -H 'Authorization:tyladfadiwkxceieixweiex747' --form nameupload=@Yourfile http://localhost:8080/upload\n\n```\n\nVisualizing all logs generated in real time\n```\n# docker exec id-container tail -f /go/goupload/goupload.log\n# or\n# tail -f /yourpath/docker/goupload.log\n\n```\n\nListing container ports\n```\n# docker exec id-container nmap localhost\n```\n\nListing the processes of your container\n```\n# docker exec id-container ps aux\n\n```\n\nHere is where the running program is located, here will be generated the no-sql boltdb database, \nthe access log and where it will store the uploads made by the client\n\n```\n# docker exec id-container ls -lh /go/goupload\n# or\n# ls -lh /yourpath/docker/\n```\n\nHere are all sources of goupload\n```\n# docker exec id-container ls -lh /go/src/github.com/jeffotoni\n\n```\n\nIf you want to get into the container to have a look or change something that you think\nEnter the container\n```\n# docker exec -ti id-container /bin/sh\n```\n\n## Install local on your machine \n\nClone this repo into your GOPATH\n```\ngit clone https://github.com/jeffotoni/goupload\n\n```\n\n## Get dependencies\n\n```sh\ngot get -u github.com/boltdb/bolt\ngot get -u github.com/gorilla/mux\ngot get -u github.com/jeffotoni/goupload\n\n```\n\n## Run the program local on your machine\n\n```go\n# go run goupload.go start\nServices successfully tested\nHost: localhost\nScheme:http\nPort: 8080\nInstance POST  http://localhost:8080/upload\nLoaded service\n\n```\n\n## Logs generated from the server \n\n```\n#tail -f goupload.log\n2017/04/01 23:12:11 libupload.go:186: ......................start upload .........................\n2017/04/01 23:12:11 libupload.go:187: Authorization: tyladfadiwkxceieixweiex747\n2017/04/01 23:12:11 libupload.go:188: Path dir: uploads/tyladfadiwkxceieixweiex747\n2017/04/01 23:12:11 libupload.go:189: Path file: uploads/tyladfadiwkxceieixweiex747/file2.pdf\n2017/04/01 23:12:11 libupload.go:190: File: file2.pdf\n2017/04/01 23:12:11 libupload.go:191: Size:  0\n2017/04/01 23:12:11 libupload.go:192: Allowed:  500 Mb\n2017/04/01 23:12:11 libupload.go:193: Copied: 246281 bytes\n2017/04/01 23:12:11 libupload.go:194: Copied: 240 Kb\n2017/04/01 23:12:11 libupload.go:195: Copied: 0 Mb\n2017/04/01 23:12:11 libupload.go:196: Database key: tyladfadiwkxceieixweiex747/file2.pdf\n2017/04/01 23:12:11 libupload.go:198: ...........................................................\n\n```\n\nStopping the server\n\n```go\n# go run goupload.go stop\n\n```\n\n## You can also build goupload.go \n\n```go\n# go build goupload.go\n# ./goupload.go\nServices successfully tested\nHost: localhost\nScheme:http\nPort: 8080\nInstance POST  http://localhost:8080/upload\nLoaded service\n\n```\n\n## Install this repo into your GOPATH\nCheck out your GOPATH, when install goupload the executable will go to your bin\n\n```sh\n# cd goupload \u0026\u0026 go install\n# goupload\nServices successfully tested\nHost: localhost\nScheme:http\nPort: 8080\nInstance POST  http://localhost:8080/upload\nLoaded service\n\n```\n\n## Body function\n\nBody of main function\n\n```go\n\n/** [Main function] */\n\nfunc main() {\n\n\t// start and stop server\n\n\tif len(os.Args) \u003e 1 {\n\n\t\tcommand := os.Args[1]\n\n\t\tif command != \"\" {\n\n\t\t\tif command == \"start\" {\n\n\t\t\t\t// Start server\n\n\t\t\t\tlibupload.StartUploadServer()\n\n\t\t\t} else if command == \"stop\" {\n\n\t\t\t\t// Stop server\n\n\t\t\t\tfmt.Println(\"under development!!!!\")\n\n\t\t\t} else {\n\n\t\t\t\tfmt.Println(\"Usage: server {start|stop}\")\n\t\t\t}\n\n\t\t} else {\n\n\t\t\tcommand = \"\"\n\t\t\tfmt.Println(\"No command given\")\n\t\t}\n\t} else {\n\n\t\tfmt.Println(\"Usage: server {start|stop}\")\n\t}\n}\n\n```\n\nBody of StartUploadServer\n\n```go\n\n// using startUploadServer restful server upload\n// This method will generate the handlerFunc\n// for our api upload\nfunc StartUploadServer() {\n\n\t// Testing boltdb database\n\t// Start ping database\n\t// Creating ping ok\n\tgbolt.Save(\"Ping\", \"ok\")\n\n\t// Testing whether it was recorded\n\t// and read on the boltdb, we\n\t// recorded a Ping and then\n\t// read it back.\n\tif gbolt.Get(\"Ping\") != \"ok\" {\n\n\t\tfmt.Println(\"Services Error Data Base!\")\n\t\tos.Exit(1)\n\t}\n\n\t// Showing the status screen\n\tfmt.Println(\"Services successfully tested\")\n\tfmt.Println(\"Host: \" + Host)\n\tfmt.Println(\"Scheme:\" + Scheme)\n\tfmt.Println(\"Port: \" + Port)\n\tfmt.Println(\"Instance POST \", UrlUpload())\n\tfmt.Println(\"Loaded service\")\n\n\t// create route\n\trouter := mux.NewRouter().StrictSlash(true)\n\trouter.Handle(\"/\", http.FileServer(http.Dir(\"message\")))\n\n\trouter.\n\t\tHandleFunc(\"/upload\", func(w http.ResponseWriter, r *http.Request) {\n\n\t\t\tif r.Method == \"POST\" {\n\n\t\t\t\t// Build the method here\n\t\t\t\tfmt.Fprintln(w, \"http \", 200, \"ok\")\n\t\t\t\tUploadFile(w, r)\n\n\t\t\t} else if r.Method == \"GET\" {\n\n\t\t\t\tfmt.Fprintln(w, \"http \", 500, \"Not authorized / Allowed method POST\")\n\n\t\t\t} else {\n\n\t\t\t\tfmt.Fprintln(w, \"http \", 500, \"Not authorized / Allowed method POST\")\n\t\t\t}\n\t\t})\n\n\t// Configuration of our ListenAndServer, [\n\t// here we put all our configurations that\n\t// the server will manage\n\thttpConf = \u0026http.Server{\n\n\t\tHandler: router,\n\t\tAddr:    HostHttp + \":\" + Port,\n\n\t\t// Good idea!!! Good live!!!\n\t\tWriteTimeout: 5 * time.Second,\n\t\tReadTimeout:  5 * time.Second,\n\t}\n\n\tlog.Fatal(httpConf.ListenAndServe())\n}\n\n\n```\n\nBody of main function UploadFile\n\nUploadfile implemented method will create a folder as the name of the token and stored the file in this created folder, this method checks the maximum size of the upload to allow or not to upload to the server.\n\n```go\n\n// using UploadFile method implemented\n// This method will copy the file that is\n// coming in by the http.Request handler\n// and copy to our physical disk file\nfunc UploadFile(w http.ResponseWriter, r *http.Request) {\n\n\t// Setting the maximum size\n\t// of the mega byte upload\n\tUploadSize = 500\n\n\t// Capturing Authorization of Header\n\tAutorization := r.Header.Get(\"Authorization\")\n\n\tif Autorization == \"\" {\n\n\t\tfmt.Fprintln(w, \"\", 500, \"Not Authorized\")\n\n\t} else {\n\n\t\t// Checking Authorization\n\t\t// if it is enabled for access\n\t\tif Autorization == AUTHORIZATION {\n\n\t\t\t// Valid user\n\t\t\tacessekey := Autorization\n\n\t\t\t// Converting byte file size to mega bytes\n\t\t\tsizeMaxUpload := r.ContentLength / 1048576 ///Mb\n\n\t\t\t// If the file size is larger than allowed,\n\t\t\t// do not allow uploading and send\n\t\t\t// a message to the client\n\t\t\tif sizeMaxUpload \u003e UploadSize {\n\n\t\t\t\tfmt.Println(\"The maximum upload size: \", UploadSize, \"Mb is large: \", sizeMaxUpload, \"Mb\")\n\t\t\t\tfmt.Fprintln(w, \"\", 500, \"Unsupported file size max: \", UploadSize, \"Mb\")\n\n\t\t\t} else {\n\n\t\t\t\t// field upload\n\t\t\t\tfile, handler, _ := r.FormFile(\"nameupload\")\n\t\t\t\tdefer file.Close()\n\n\t\t\t\t///create dir to key\n\t\t\t\tpathUpKeyUser := PathLocal + acessekey\n\n\t\t\t\t//IF NO EXIST\n\t\t\t\tif !ExistDir(pathUpKeyUser) {\n\n\t\t\t\t\tos.MkdirAll(pathUpKeyUser, 0777)\n\t\t\t\t}\n\n\t\t\t\t// Mounting the physical path where the\n\t\t\t\t// file will be uploaded, the folder has\n\t\t\t\t// nly one level, its access\n\t\t\t\t// code Autorization + name file\n\t\t\t\tpathUserAcess := PathLocal + acessekey + \"/\" + handler.Filename\n\n\t\t\t\t// copy file and write\n\t\t\t\tf, _ := os.OpenFile(pathUserAcess, os.O_WRONLY|os.O_CREATE, 0777)\n\t\t\t\tdefer f.Close()\n\n\t\t\t\tbytes, _ := io.Copy(f, file)\n\t\t\t\tkeyfile := acessekey + \"/\" + handler.Filename\n\n\t\t\t\t// Saving the result of the upload\n\t\t\t\t// in the no-sql database\n\t\t\t\tSaveDb(keyfile, handler.Filename, bytes, pathUserAcess)\n\n\t\t\t\t// Generates a log of everything that\n\t\t\t\t// happens on the server\n\t\t\t\tflag.Parse()\n\t\t\t\tglogs.LogNew(*glogs.PathLog)\n\n\t\t\t\tglogs.Log.Printf(\"......................start upload .........................\")\n\t\t\t\tglogs.Log.Printf(\"Authorization: %s\\n\", AUTHORIZATION)\n\t\t\t\tglogs.Log.Printf(\"Path dir: %s\\n\", pathUpKeyUser)\n\t\t\t\tglogs.Log.Printf(\"Path file: %s\\n\", pathUserAcess)\n\t\t\t\tglogs.Log.Printf(\"File: %s\\n\", handler.Filename)\n\t\t\t\tglogs.Log.Println(\"Size: \", sizeMaxUpload)\n\t\t\t\tglogs.Log.Println(\"Allowed: \", UploadSize, \"Mb\")\n\t\t\t\tglogs.Log.Printf(\"Copied: %v bytes\\n\", bytes)\n\t\t\t\tglogs.Log.Printf(\"Copied: %v Kb\\n\", bytes/1024)\n\t\t\t\tglogs.Log.Printf(\"Copied: %v Mb\\n\", bytes/1048576)\n\t\t\t\tglogs.Log.Printf(\"Database key: %s\\n\", keyfile)\n\n\t\t\t\tglogs.Log.Printf(\"...........................................................\")\n\t\t\t\tglogs.Log.Printf(\" \")\n\n\t\t\t\ttime.Sleep(1 * time.Second)\n\n\t\t\t\tfmt.Fprintln(w, \"\", 200, \"OK\")\n\n\t\t\t}\n\n\t\t} else {\n\n\t\t\tfmt.Fprintln(w, \"\", 500, \"access denied\")\n\t\t}\n\t}\n}\n\n```\n\nBody of main function Connect\n```go\n// using Connect\n// This method is what does\n// and returns our instance for access\n// to our no-sql database.\nfunc Connect() *DB {\n\n\tif db2 == nil {\n\n\t\t// Singleton the bank has to close every call,\n\t\t// save, update, get etc ..\n\t\t//\n\t\t// Testing and verifying if there is a directory\n\t\t// and file of our bucket, if it does not exist\n\t\t// it creates the directory and the file so that\n\t\t// we can manipulate all our bucket.\n\t\t//\n\t\t// Remember that boltdb with the open function also creates.\n\t\tif err := DataBaseTest(PathDb); err != nil {\n\n\t\t\tlog.Fatal(\"Error Test database\", err)\n\t\t}\n\n\t\t// Here is the object responsible for\n\t\t// allowing calls to the methods, such as Get, Save, etc.\n\t\tdbbolt, err = bolt.Open(PathDb, 0600, \u0026bolt.Options{Timeout: 1 * time.Second})\n\n\t\tif err != nil {\n\n\t\t\tlog.Fatal(\"connect error: \", err)\n\t\t}\n\n\t\t// We create a new reference\n\t\t// just to facilitate\n\t\t// understanding and syntax\n\t\tdb2 = \u0026DB{dbbolt}\n\t}\n\n\treturn db2\n}\n\n```\n\nBody of main function SaveDb\n```go\n\nfunc SaveDb(keyfile string, namefile string, sizefile int64, pathFile string) error {\n\n\ttimes := fmt.Sprintf(\"%s\", time.Now())\n\n\tstringJson := JsonDataDb{keyfile, namefile, sizefile, pathFile, times}\n\n\trespJson, err := json.Marshal(stringJson)\n\n\trespJsonX := string(respJson)\n\n\terr = Save(keyfile, respJsonX)\n\n\tif err == nil {\n\n\t\t//fmt.Println(\"save sucess..\")\n\t\treturn nil\n\n\t} else {\n\n\t\t//fmt.Println(\"Error\", err)\n\t\treturn err\n\t}\n\n}\n\n```\n\n## Examples client\n\nUploading with Authorization\n\n```\ncurl -H 'Authorization:tyladfadiwkxceieixweiex747' --form nameupload=@nameFile.tar.bz2 http://localhost:8080/upload\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeffotoni%2Fgoupload","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjeffotoni%2Fgoupload","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeffotoni%2Fgoupload/lists"}