Fix lint issues
This commit is contained in:
parent
2695b712c2
commit
8f41afed30
5 changed files with 19 additions and 8 deletions
|
|
@ -53,7 +53,8 @@ func main() {
|
|||
<-sig
|
||||
|
||||
// Shutdown signal with grace period of 30 seconds
|
||||
shutdownCtx, _ := context.WithTimeout(serverCtx, 30*time.Second)
|
||||
shutdownCtx, cancel := context.WithTimeout(serverCtx, 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
go func() {
|
||||
<-shutdownCtx.Done()
|
||||
|
|
|
|||
|
|
@ -105,6 +105,9 @@ func getMediaResults(inputUrl string) ([]Media, string, error) {
|
|||
id := GetMD5Hash(url)
|
||||
// Look to see if we already have the media on disk
|
||||
medias, err := getAllFilesForId(id)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
if len(medias) == 0 {
|
||||
// We don't, so go fetch it
|
||||
errMessage := ""
|
||||
|
|
@ -189,11 +192,14 @@ func getAllFilesForId(id string) ([]Media, error) {
|
|||
root := getMediaDirectory(id)
|
||||
file, err := os.Open(root)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
files, _ := file.Readdirnames(0) // 0 to read all files and folders
|
||||
if len(files) == 0 {
|
||||
return nil, errors.New("ID not found")
|
||||
return nil, errors.New("ID not found: " + id)
|
||||
}
|
||||
|
||||
var medias []Media
|
||||
|
|
|
|||
|
|
@ -37,19 +37,19 @@ func streamFileToClientById(w http.ResponseWriter, r *http.Request, id string) {
|
|||
|
||||
func streamFileToClient(w http.ResponseWriter, r *http.Request, filename string) {
|
||||
// Check if file exists and open
|
||||
Openfile, err := os.Open(filename)
|
||||
defer Openfile.Close() //Close after function return
|
||||
openfile, err := os.Open(filename)
|
||||
if err != nil {
|
||||
//File not found, send 404
|
||||
http.Error(w, "File not found.", 404)
|
||||
return
|
||||
}
|
||||
defer openfile.Close()
|
||||
|
||||
// Get the Content-Type of the file
|
||||
// Create a buffer to store the header of the file in
|
||||
fileHeader := make([]byte, 100)
|
||||
//Copy the headers into the FileHeader buffer
|
||||
if _, err = Openfile.Read(fileHeader); err != nil {
|
||||
if _, err = openfile.Read(fileHeader); err != nil {
|
||||
log.Error().Msgf("File not found, couldn't open for reading at %s %v", filename, err)
|
||||
http.Error(w, "File not found", 404)
|
||||
return
|
||||
|
|
@ -64,7 +64,7 @@ func streamFileToClient(w http.ResponseWriter, r *http.Request, filename string)
|
|||
|
||||
// Send the file
|
||||
// We read n bytes from the file already, so we reset the offset back to 0
|
||||
if _, err = Openfile.Seek(0, 0); err != nil {
|
||||
if _, err = openfile.Seek(0, 0); err != nil {
|
||||
log.Error().Msgf("Error seeking into file %s %v", filename, err)
|
||||
http.Error(w, "File not found", 404)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ func GetInstalledVersion() string {
|
|||
log.Error().Err(err).Msgf("Error getting installed version")
|
||||
}
|
||||
|
||||
version := strings.TrimSpace(string(s.Bytes()))
|
||||
version := strings.TrimSpace(s.String())
|
||||
if version == "" {
|
||||
version = "unknown"
|
||||
}
|
||||
|
|
|
|||
6
tidy.sh
6
tidy.sh
|
|
@ -3,4 +3,8 @@ set -ex
|
|||
|
||||
go get -u ./...
|
||||
go mod tidy
|
||||
go fmt ./...
|
||||
go fmt ./...
|
||||
|
||||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.62.0
|
||||
$(go env GOPATH)/bin/golangci-lint --version
|
||||
$(go env GOPATH)/bin/golangci-lint run
|
||||
Loading…
Reference in a new issue