reworking errors + now using a working dir for our converter

This commit is contained in:
Julien Neuhart
2018-03-30 09:19:37 +02:00
parent e847c86baa
commit a882b7e5c5
16 changed files with 203 additions and 241 deletions

View File

@@ -1,15 +0,0 @@
package http
import "fmt"
type notAuthorizedContentTypeError struct{}
func (e *notAuthorizedContentTypeError) Error() string {
return fmt.Sprintf("Accepted values for 'Content-Type': %s, %s, %s, %s", PDFContentType, HTMLContentType, OctetStreamContentType, MultipartFormDataContentType)
}
type notAuthorizedFileContentTypeError struct{}
func (e *notAuthorizedFileContentTypeError) Error() string {
return fmt.Sprintf("Unable to detect a file 'Content-Type'")
}

View File

@@ -1,6 +1,7 @@
package http
import (
"fmt"
"net/http"
"os"
"strings"
@@ -16,6 +17,12 @@ const (
MultipartFormDataContentType ContentType = "multipart/form-data"
)
type notAuthorizedContentTypeError struct{}
func (e *notAuthorizedContentTypeError) Error() string {
return fmt.Sprintf("Accepted values for 'Content-Type': %s, %s, %s, %s", PDFContentType, HTMLContentType, OctetStreamContentType, MultipartFormDataContentType)
}
func FindAuthorizedContentType(h http.Header) (ContentType, error) {
ct := findContentType(h.Get("Content-Type"), HTMLContentType, OctetStreamContentType, MultipartFormDataContentType)
if ct == "" {
@@ -25,6 +32,12 @@ func FindAuthorizedContentType(h http.Header) (ContentType, error) {
return ct, nil
}
type notAuthorizedFileContentTypeError struct{}
func (e *notAuthorizedFileContentTypeError) Error() string {
return fmt.Sprintf("Unable to detect a file 'Content-Type'")
}
func SniffContentType(f *os.File) (ContentType, error) {
// only the first 512 bytes are used to sniff the content type.
buffer := make([]byte, 512)