{"id":18023625,"url":"https://github.com/jeffotoni/gofileserver","last_synced_at":"2025-03-27T00:30:39.742Z","repository":{"id":134047298,"uuid":"86202747","full_name":"jeffotoni/gofileserver","owner":"jeffotoni","description":"Simple RESTFUL API demo server written on Go (golang) user S3, postgresql, Upload, Download","archived":false,"fork":false,"pushed_at":"2017-11-28T01:22:09.000Z","size":50397,"stargazers_count":2,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-22T17:24:46.023Z","etag":null,"topics":["aws-s3","cloud","curl","database","go","golang","restful","restful-webservices"],"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-26T02:43:49.000Z","updated_at":"2023-12-07T04:28:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"246d3ea0-8c3a-4f96-a9b4-4e7282b52951","html_url":"https://github.com/jeffotoni/gofileserver","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%2Fgofileserver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffotoni%2Fgofileserver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffotoni%2Fgofileserver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffotoni%2Fgofileserver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jeffotoni","download_url":"https://codeload.github.com/jeffotoni/gofileserver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245760541,"owners_count":20667886,"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":["aws-s3","cloud","curl","database","go","golang","restful","restful-webservices"],"created_at":"2024-10-30T07:10:02.697Z","updated_at":"2025-03-27T00:30:39.727Z","avatar_url":"https://github.com/jeffotoni.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gofileserver\nThe objective of this project is purely didactic, it is an attempt to solve the problem of competition and parallelism that the project will assume with uploading, reading and downloading files on disk and for the cloud.\n\nSimple RESTFUL API demo server written in Go (golang) in order to solve problems of recording, uploading and downloading files to disk and the Amazon cloud using S3 for various regions, Google Cloud or any other cloud service that you want to implement, using postgresql as Database and token authentication.\nThe services of amazon s3 were first implemented.\n\n\n## Used libraries:\n- https://github.com/lib/pq - Sql Database.\n- https://gopkg.in/gcfg.v1 - Text-based configuration files with \"name=value\" pairs grouped into sections (gcfg files).\n- https://github.com/aws/aws-sdk-go/aws - Package sdk Aws Amazon\n- https://github.com/gorilla/mux - Implements a request router and dispatcher for matching incoming requests\n\n---\n* [A small summary](#summary)\n* [Install](#install)\n* [Structure](#structure)\n* [Run](#runprogram)\n* [Examples Client](#examples-client)\n* [Register User](#register-user)\n* [Upload File](#upload-files)\n* [Download Files](#download-files)\n\n## A small summary operating system\n\n* [Gofileserver.go]\n\nThis program is responsible for managing and controlling our APIS.\n\nThe upload is done on the local server always, there is a configuration file to determine some features of the config.gcfg system.\nEverything is recorded in the database.\nAuthentication for upload upload was done in 2 ways.\n\nThe download checks if the file is local or if it has already been sent to the cloud, if it is still on the local server the system will download locally, otherwise it checks on which cloud server it is to download from the cloud.\n\nThe register and token is responsible for creating users and receiving the access token, and also with the possibility to view the tokem with username and password.\n\n\n* [Gofileupload.go]\n\nThis program is responsible for downloading the files that are found on the local server to the cloud, the system evaluates the availability and uploads to the cloud.\n\nIt is not deleted files locally, they are deleted in a second time for security, they are checked if it really is in the cloud before physically removes them.\n\n* [Gofileremove.go]\n\nThis program is responsible for monitoring the files on disk so they can be removed, it checks in the cloud if the object is actually there, and if it does remove it from the disk physically.\n\n* [Goserversite.go]\n\nThis program is just an attempt to create an interface to simulate what the client will see how the files on our platform are.\n\n\n## Install\n\n```sh\ngit clone https://github.com/jeffotoni/gofileserver\n```\n\nWith a [correctly configured](https://golang.org/doc/code.html#Workspaces) Go toolchain:\n\n```sh\ngo get -u github.com/lib/pq\ngo get -u gopkg.in/gcfg.v1\ngo get -u github.com/aws/aws-sdk-go/aws\ngo get -u github.com/gorilla/mux\ngo get -u github.com/jeffotoni/gofileserver\n```\n\nConfiguring the environment to run sdk amazon API\n[`SDK Examples`] (https://github.com/aws/aws-sdk-go/tree/master/example)\n\n```\nmkdir ~/.aws/\nvim ~/.aws/config\n\n[default]\nregion = us-east-1\noutput = \n\nvim ~/.aws/credentials\n\n[default]\naws_access_key_id = AKIX1234567890\naws_secret_access_key = MY-SECRET-KEY\n```\n\nCreating postgresql database \n[`Installing`] (Postgres http://www.postgresguide.com/setup/install.html)\n\n```sh\ncreateuser ukkobox -U postgres\npsql -d template1 -U postgres\npsql=\u003e alter user ukkobox password 'pass123'\ncreatedb ukkobox -U postgres -O ukkobox -E UTF-8 -T template0\npsql ukkobox -U postgres -f tables/ukkobox.sql\n```\n\nEdit the configuration file\n\n```\nvim config/config.gcfg\n```\n\nCrontab edit the configuration / crontab -e\n```\n*/5 * * * * cd /pathprojeto/gofileserver/src \u0026\u0026 go run gofileupload.go \u003e\u003e /pathprojeto/gofileserver/src/gofileupload.log\n\n*/10 * * * * cd /pathprojeto/gofileserver/src \u0026\u0026 go run gofileremove.go \u003e\u003e /pathprojeto/gofileserver/src/gofileremove.log\n\n```\n\n## Structure of the program\n\n```go\n- gofileserver\n\t- bin \n\t- config\n\t\t- config.go\n\t\t- config.gcfg\n\t- dirmsg\n\t\twelcome.html\n\t- pkg\t\n\t\t- fcrypt\n\t\t- gcheck\n\t\t- gofrlib\n\t\t- gofslib\n\t\t- gofuplib\n\t\t- postgres\n\t\t\t- connection\n\t- tables\n\t\tukkobox.sql\n\t- uploads\n\t- views\n\t\tindex.html\n\n\tgofileserver.go\t\n\tServer to register users, receive and send files to the file server\n\t\n\n\tgofileupload.go\n\tScans all local structure and sends the files to servers in the \n\tcloud: Cloud Google, Amazon, DigitalOcean\n\t\n\n\tgofileremove.go\n\tScrolls the structure checks whether the files are safe in the \n\tcloud and removes the location\n\t\n\tgoserversite.go\n\tA template under construction so customers can manage, view, download \n\ttheir uploaded as an online bucket\n\t\n```\n\n## Run the program\n\n```go\ngo run gofileserver.go \n\nConect port : 80\nConect database:  ukkobox\nDatabase User:  ukkobox\nInstance /register\nInstance /token\nInstance /upload\nInstance /download\n\nOR New gofileserver \n\ngo run gofileserver2.go start\n\nTesting services\nPostgres:  ok\nConfig:  ok\nHost: localhost\nSchema: http\nServer listening port :  4001\nDatabase ukkobox\nDatabase User:  ukkobox\nInstance POST  http://localhost:4001/register\nInstance GET   http://localhost:4001/token\nInstance POST  http://localhost:4001/upload\nInstance GET   http://localhost:4001/download\nLoaded service\n\n```\n\nStopping the server\n\n```go\ngo run gofileserver2.go stop\n```\n\nCompiling gofileserver or gofileserver2\n\n```go\ngo build gofileserver.go \ngo build gofileserver2.go \n```\n\nBody of main function\n\n```go\n\nfunc main() {\n\n\t//config global\n\n\tcfg := sfconfig.GetConfig()\n\n\tfmt.Println(\"Server listening port : \", cfg.Section.ServerPort)\n\tfmt.Println(\"Database\", cfg.Section.Database)\n\tfmt.Println(\"Database User: \", cfg.Section.User)\n\n\tfmt.Println(\"Instance POST /register\")\n\tfmt.Println(\"Instance GET /token\")\n\tfmt.Println(\"Instance POST /upload\")\n\tfmt.Println(\"Instance GET /download\")\n\n\t///create route\n\trouter := mux.NewRouter().StrictSlash(true)\n\n\trouter.Handle(\"/\", http.FileServer(http.Dir(\"../dirmsg\")))\n\n\trouter.\n\t\tHandleFunc(\"/register\", func(w http.ResponseWriter, r *http.Request) {\n\n\t\t\tif r.Method == http.MethodPost {\n\n\t\t\t\tgofslib.RegisterUserJson(w, r)\n\n\t\t\t} else if r.Method == http.MethodGet {\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\trouter.\n\t\tHandleFunc(\"/token\", func(w http.ResponseWriter, r *http.Request) {\n\n\t\t\tif r.Method == http.MethodPost {\n\n\t\t\t\t//gofslib.GetTokenUser(w, r)\n\t\t\t\tfmt.Fprintln(w, \"http \", 500, \"Not authorized / Allowed method GET\")\n\n\t\t\t} else if r.Method == http.MethodGet {\n\n\t\t\t\tgofslib.GetTokenUser(w, r)\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\trouter.\n\t\tHandleFunc(\"/upload\", func(w http.ResponseWriter, r *http.Request) {\n\n\t\t\tif r.Method == http.MethodPost {\n\n\t\t\t\tgofslib.UploadFileEasy(w, r)\n\n\t\t\t} else if r.Method == http.MethodGet {\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\trouter.\n\t\tHandleFunc(\"/download/{name}\", func(w http.ResponseWriter, r *http.Request) {\n\n\t\t\tpathFileLocal := \"../msg/error-download.txt\"\n\n\t\t\tif r.Method == http.MethodGet {\n\n\t\t\t\tgofslib.DownloadFile(w, r)\n\n\t\t\t} else if r.Method == http.MethodGet {\n\n\t\t\t\thttp.ServeFile(w, r, pathFileLocal)\n\n\t\t\t\tfmt.Fprintln(w, \"http \", 500, \"Not authorized\")\n\n\t\t\t} else {\n\n\t\t\t\thttp.ServeFile(w, r, pathFileLocal)\n\t\t\t\tfmt.Fprintln(w, \"http \", 500, \"Not authorized\")\n\t\t\t}\n\t\t})\n\n\t\n\tconfsc := \u0026http.Server{\n\n\t\tHandler: router,\n\t\tAddr:    \"127.0.0.1:\" + cfg.Section.ServerPort,\n\n\t\t// Good idea, good live!!!\n\n\t\tWriteTimeout: 10 * time.Second,\n\t\tReadTimeout:  10 * time.Second,\n\t}\n\n\tlog.Fatal(confsc.ListenAndServe())\n\n}\n\n```\n\n```go\ngo build gofileserver2.go \n```\n\nBody of main function \n\n```go\n\n/** Environment variables and keys */\n\nvar (\n\tconfServer    *http.Server\n\tAUTHORIZATION = `bc8c154ebabc6f3da724e9x5fef79238`\n\tsocketfileTmp = `gofileserver.red`\n\tsocketfile    = `gofileserver.lock`\n\tkeyCrypt      = `pKv9MQQIDAQABAmEApvlExjvPp0mYs/i`\n)\n\nfunc main() {\n\n\t// Command line for 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\tstartFileServer()\n\n\t\t\t} else if command == \"stop\" {\n\n\t\t\t\t// Stop server\n\n\t\t\t\tfmt.Println(\"stop service...\")\n\t\t\t\tNewRequestGetStop()\n\n\t\t\t} else {\n\n\t\t\t\tfmt.Println(\"Usage: gofileserver {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: gofileserver {start|stop}\")\n\t}\n}\n\n```\n\nBody of main function  startFileServer(){}\n\n```go\n\nfunc startFileServer() {\n\n\tcfg := sfconfig.GetConfig()\n\n\tfmt.Println(\"Testing services\")\n\tfmt.Println(\"Postgres: \", connection.TestDb())\n\tfmt.Println(\"Config: \", sfconfig.TestConfig())\n\n\tfmt.Println(\"Host: Localhost\")\n\tfmt.Println(\"Schema: http\")\n\tfmt.Println(\"Server listening port : \", cfg.Section.ServerPort)\n\tfmt.Println(\"Database\", cfg.Section.Database)\n\tfmt.Println(\"Database User: \", cfg.Section.User)\n\n\tfmt.Println(\"Instance POST http://localhost:\" + cfg.Section.ServerPort + \"/register\")\n\tfmt.Println(\"Instance GET  http://localhost:\" + cfg.Section.ServerPort + \"/token\")\n\tfmt.Println(\"Instance POST http://localhost:\" + cfg.Section.ServerPort + \"/upload\")\n\tfmt.Println(\"Instance GET  http://localhost:\" + cfg.Section.ServerPort + \"/download\")\n\tfmt.Println(\"Loaded service\")\n\n\t///create route\n\n\trouter := mux.NewRouter().StrictSlash(true)\n\t//router.Host(\"Localhost\")\n\n\trouter.Handle(\"/\", http.FileServer(http.Dir(\"../dirmsg\")))\n\t\n\trouter.\n\t\tHandleFunc(\"/ping\", func(w http.ResponseWriter, r *http.Request) {\n\n\t\t\tif r.Method == http.MethodPost || r.Method == http.MethodGet {\n\n\t\t\t\tfmt.Fprintln(w, \"http \", 200, `{\"msg\":\"pong\"}`)\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\trouter.\n\t\tHandleFunc(\"/stop/{id}\", func(w http.ResponseWriter, r *http.Request) {\n\n\t\t\tif r.Method == http.MethodGet {\n\n\t\t\t\tHeaderAutorization := r.Header.Get(\"Authorization\")\n\n\t\t\t\tfmt.Println(\"HeaderAutorization: \", HeaderAutorization)\n\n\t\t\t\tif HeaderAutorization == \"\" {\n\n\t\t\t\t\tfmt.Fprintln(w, \"http \", 500, \"Not authorized\")\n\n\t\t\t\t} else {\n\n\t\t\t\t\tif HeaderAutorization == AUTHORIZATION {\n\n\t\t\t\t\t\tvars := mux.Vars(r)\n\t\t\t\t\t\tidStopServer := vars[\"id\"]\n\n\t\t\t\t\t\tfmt.Println(\"Id Token: \", idStopServer)\n\t\t\t\t\t\tfmt.Println(\"Id TFile: \", ReadFile())\n\n\t\t\t\t\t\tif idStopServer == ReadFile() {\n\n\t\t\t\t\t\t\tfmt.Fprintln(w, \"http \", 200, \"ok stop\")\n\t\t\t\t\t\t\tStopListenAndServe()\n\n\t\t\t\t\t\t} else {\n\n\t\t\t\t\t\t\tfmt.Fprintln(w, \"http \", 500, \"Not authorized\")\n\t\t\t\t\t\t}\n\n\t\t\t\t\t} else {\n\n\t\t\t\t\t\tfmt.Fprintln(w, \"http \", 500, \"Not authorized\")\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t} else if r.Method == http.MethodPost {\n\n\t\t\t\tfmt.Fprintln(w, \"http \", 500, \"Not authorized\")\n\n\t\t\t} else {\n\n\t\t\t\tfmt.Fprintln(w, \"http \", 500, \"Not authorized\")\n\t\t\t}\n\t\t})\n\n\trouter.\n\t\tHandleFunc(\"/register\", func(w http.ResponseWriter, r *http.Request) {\n\n\t\t\tif r.Method == http.MethodPost {\n\n\t\t\t\tgofslib.RegisterUserJson(w, r)\n\n\t\t\t} else if r.Method == http.MethodGet {\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\trouter.\n\t\tHandleFunc(\"/token\", func(w http.ResponseWriter, r *http.Request) {\n\n\t\t\tif r.Method == http.MethodPost {\n\n\t\t\t\t//gofslib.GetTokenUser(w, r)\n\t\t\t\tfmt.Fprintln(w, \"http \", 500, \"Not authorized / Allowed method GET\")\n\n\t\t\t} else if r.Method == http.MethodGet {\n\n\t\t\t\tgofslib.GetTokenUser(w, r)\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\trouter.\n\t\tHandleFunc(\"/upload\", func(w http.ResponseWriter, r *http.Request) {\n\n\t\t\tif r.Method == http.MethodPost {\n\n\t\t\t\tgofslib.UploadFileEasy(w, r)\n\n\t\t\t} else if r.Method == http.MethodGet {\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\trouter.\n\t\tHandleFunc(\"/download/{name}\", func(w http.ResponseWriter, r *http.Request) {\n\n\t\t\tpathFileLocal := \"../msg/error-download.txt\"\n\n\t\t\tif r.Method == http.MethodGet {\n\n\t\t\t\tgofslib.DownloadFile(w, r)\n\n\t\t\t} else if r.Method == http.MethodGet {\n\n\t\t\t\thttp.ServeFile(w, r, pathFileLocal)\n\n\t\t\t\tfmt.Fprintln(w, \"http \", 500, \"Not authorized\")\n\n\t\t\t} else {\n\n\t\t\t\thttp.ServeFile(w, r, pathFileLocal)\n\t\t\t\tfmt.Fprintln(w, \"http \", 500, \"Not authorized\")\n\t\t\t}\n\t\t})\n\n\tconfServer = \u0026http.Server{\n\n\t\tHandler: router,\n\t\tAddr:    cfg.Section.Host + \":\" + cfg.Section.ServerPort,\n\n\t\t// Good idea, good live!!!\n\n\t\tWriteTimeout: 10 * time.Second,\n\t\tReadTimeout:  10 * time.Second,\n\t}\n\n\tPASS_URL_MD5 := fcrypt.CreateTokenStrong()\n\tWriteFile(PASS_URL_MD5)\n\n\tlog.Fatal(confServer.ListenAndServe())\n}\n\n```\n\nBody of main function  HandleFunc /stop/idEncrypted\n\n```go\nrouter.\n\t\tHandleFunc(\"/stop/{id}\", func(w http.ResponseWriter, r *http.Request) {\n\n\t\t\tif r.Method == http.MethodGet {\n\n\t\t\t\tHeaderAutorization := r.Header.Get(\"Authorization\")\n\n\t\t\t\tfmt.Println(\"HeaderAutorization: \", HeaderAutorization)\n\n\t\t\t\tif HeaderAutorization == \"\" {\n\n\t\t\t\t\tfmt.Fprintln(w, \"http \", 500, \"Not authorized\")\n\n\t\t\t\t} else {\n\n\t\t\t\t\tif HeaderAutorization == AUTHORIZATION {\n\n\t\t\t\t\t\tvars := mux.Vars(r)\n\t\t\t\t\t\tidStopServer := vars[\"id\"]\n\n\t\t\t\t\t\tfmt.Println(\"Id Token: \", idStopServer)\n\t\t\t\t\t\tfmt.Println(\"Id TFile: \", ReadFile())\n\n\t\t\t\t\t\tif idStopServer == ReadFile() {\n\n\t\t\t\t\t\t\tfmt.Fprintln(w, \"http \", 200, \"ok stop\")\n\t\t\t\t\t\t\tStopListenAndServe()\n\n\t\t\t\t\t\t} else {\n\n\t\t\t\t\t\t\tfmt.Fprintln(w, \"http \", 500, \"Not authorized\")\n\t\t\t\t\t\t}\n\n\t\t\t\t\t} else {\n\n\t\t\t\t\t\tfmt.Fprintln(w, \"http \", 500, \"Not authorized\")\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t} else if r.Method == http.MethodPost {\n\n\t\t\t\tfmt.Fprintln(w, \"http \", 500, \"Not authorized\")\n\n\t\t\t} else {\n\n\t\t\t\tfmt.Fprintln(w, \"http \", 500, \"Not authorized\")\n\t\t\t}\n\t\t})\n\n```\n\nBody of main function  StopListenAndServe\n\n```go\nfunc StopListenAndServe() {\n\n\tfmt.Println(\"stopping Server File...\")\n\tconfServer.Close()\n\tconfServer.Shutdown(nil)\n\tRemoveFile(socketfile)\n}\n```\n\nBody of main function  [WriteFileCrypt Encrypting the contents of the file]\n\n```go\nfunc WriteFileCrypt(sname string) {\n\n\t// get key\n\tkey := []byte(keyCrypt) // 32 bytes\n\n\tfile, _ := os.Open(sname) // For read access.\n\n\tfi, _ := file.Stat()\n\tdata := make([]byte, 16*fi.Size())\n\tcount, _ := file.Read(data)\n\n\tfile_cry, _ := os.Create(socketfile)\n\tdefer file_cry.Close()\n\n\tciphertext, _ := fcrypt.Encrypt(key, data[:count])\n\tfile_cry.Write(ciphertext)\n}\n\n```\n\nBody of main function  [NewRequestGetStop Encrypts the id of the URL]\n\n```go\n\n/** [NewRequestGetStop This method will stop the server, it makes a Request Get for itself telling the server to stop] */\n\nfunc NewRequestGetStop() {\n\n\tcfg := sfconfig.GetConfig()\n\n\t//Read generated key to generate the url\n\n\tPASS_URL_MD5 := ReadFile()\n\n\tif PASS_URL_MD5 != \"\" {\n\n\t\t// Create url to trigger a GET for us restful\n\n\t\tURL_STOP := cfg.Section.Schema + \"://\" + cfg.Section.Host + \":\" + cfg.Section.ServerPort + \"/stop/\" + PASS_URL_MD5\n\n\t\t// Starting our instance to send a NewRequest to our restful\n\n\t\tclient := \u0026http.Client{}\n\t\tr, err := http.NewRequest(\"GET\", URL_STOP, nil)\n\t\tif err != nil {\n\n\t\t\tfmt.Sprint(err)\n\t\t\tos.Exit(1)\n\t\t}\n\n\t\tr.Header.Add(\"Authorization\", AUTHORIZATION)\n\t\tr.Header.Add(\"Accept\", \"application/text-plain\")\n\t\t_, errx := client.Do(r)\n\t\tif errx != nil {\n\n\t\t\tlog.Print(errx)\n\t\t\tos.Exit(1)\n\t\t}\n\n\t} else {\n\n\t\tfmt.Println(\"NewRequestGetStop Error URL \")\n\t\tos.Exit(1)\n\t}\n}\n\n```\n\n## Examples client\n\nTesting if the server is online with ping \n\nUsing Curl POST or GET with /ping\n\n```sh\n\ncurl -X POST http://localhost:4001/ping\n\n```\n\nreturn\n\n```sh\n\nhttp  200 {\"msg\":\"pong\"}\n\n```\n\n\nRegister user and receive access key \n\nUsing Curl - Sending in json format\n\n```\ncurl -X POST --data '{\"name\":\"jeff\",\"email\":\"mail@your.com\",\"password\":\"321\"}' \\\n-H \"Content-Type:application/json\" \\\nhttp://localhost:4001/register\n```\n\nUsing Curl - Access token\n\n```\ncurl -X GET --data '{\"email\":\"jeff1@gmail.com\",\"password\":\"321\"}' \\\n-H \"Content-Type:application/json\" \\\nhttp://localhost:4001/token\n```\n\nUploading with Authorization\n\n```\ncurl -H 'Authorization:bc8ca54ebabc6f3da724e923fef79238' \\\n--form fileupload=@nameFile.bz2 \\\nhttp://localhost:4001/upload\n```\n\nUploading with acesskey\n\n```\ncurl -F 'acesskey:bc8ca54ebabc6f3da724e923fef79238' \\\n--form fileupload=@nameFile.bz2 \\\nhttp://localhost:4001/upload\n```\n\nDownload only Authorization\n\n```\ncurl -H 'Authorization:bc8ca54ebabc6f3da724e923fef79238' \\\n-O http://localhost:4001/download/nameFile.bz2\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeffotoni%2Fgofileserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjeffotoni%2Fgofileserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeffotoni%2Fgofileserver/lists"}