refactoring. remove global state, use new logging, config functions

This commit is contained in:
2018-06-17 16:15:58 +02:00
parent d091398f05
commit 75197310bf
24 changed files with 295 additions and 476 deletions

View File

@@ -4,14 +4,13 @@ import (
"encoding/json"
"io"
"fornaxian.com/pixeldrain-web/conf"
"fornaxian.com/pixeldrain-web/log"
"github.com/Fornaxian/log"
)
// GetFile makes a file download request and returns a readcloser. Don't forget
// to close it!
func GetFile(id string) (io.ReadCloser, error) {
return getRaw(conf.ApiUrlInternal() + "/file/" + id)
func (p *PixelAPI) GetFile(id string) (io.ReadCloser, error) {
return getRaw(p.apiEndpoint + "/file/" + id)
}
// FileInfo File information object from the pixeldrain API
@@ -30,8 +29,8 @@ type FileInfo struct {
}
// GetFileInfo gets the FileInfo from the pixeldrain API
func GetFileInfo(id string) *FileInfo {
body, err := getString(conf.ApiUrlInternal() + "/file/" + id + "/info")
func (p *PixelAPI) GetFileInfo(id string) *FileInfo {
body, err := getString(p.apiEndpoint + "/file/" + id + "/info")
if err != nil {
log.Error("req failed: %v", err)

View File

@@ -2,8 +2,6 @@ package pixelapi
import (
"encoding/json"
"fornaxian.com/pixeldrain-web/conf"
)
// API error constants
@@ -34,9 +32,9 @@ type ListFile struct {
// GetList get a List from the pixeldrain API. Errors will be available through
// List.Error. Standard error checks apply.
func GetList(id string) *List {
func (p *PixelAPI) GetList(id string) *List {
var list = &List{}
body, err := getString(conf.ApiUrlInternal() + "/list/" + id)
body, err := getString(p.apiEndpoint + "/list/" + id)
if err != nil {
list.Error = errorResponseFromError(err)
return list

9
pixelapi/pixelapi.go Normal file
View File

@@ -0,0 +1,9 @@
package pixelapi
type PixelAPI struct {
apiEndpoint string
}
func New(apiEndpoint string) *PixelAPI {
return &PixelAPI{apiEndpoint}
}