diff --git a/ASClient.go b/ASClient.go index 90962dc..5e89a58 100644 --- a/ASClient.go +++ b/ASClient.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io" - "log" "net/http" "os" "time" @@ -49,8 +48,6 @@ func NewClientFromCreds(creds Creds, timeout int) (*ASClient, error) { var client *ASClient - log.Printf("[DEBUG] url: %s, username: %s, password: %s", creds.URL, creds.Username, creds.Password) - tr := &http.Transport{ MaxIdleConns: 10, IdleConnTimeout: time.Duration(timeout) * time.Second, diff --git a/Agents.go b/Agents.go index 60151a7..441f453 100644 --- a/Agents.go +++ b/Agents.go @@ -39,6 +39,9 @@ func (a *ASClient) GetAgent(agentType string, agentID int) (Agent, error) { } err = json.Unmarshal(body, &agent) + if err != nil { + return agent, err + } return agent, nil } diff --git a/ArchivalObjects.go b/ArchivalObjects.go index 2f9ce15..3903fab 100644 --- a/ArchivalObjects.go +++ b/ArchivalObjects.go @@ -4,8 +4,6 @@ import ( "encoding/json" "fmt" "io" - "regexp" - "strings" ) func (a *ASClient) GetArchivalObjectIDs(repositoryID int) ([]int, error) { @@ -91,14 +89,14 @@ func (a *ASClient) UpdateArchivalObject(repositoryId int, archivalObjectId int, return responseMessage, nil } -func getChildArchivalObjectURIs(children []ResourceTree, aos *[]string) { - for _, child := range children { - *aos = append(*aos, child.RecordURI) - if child.HasChildren { - getChildArchivalObjectURIs(child.Children, aos) - } - } -} +// func getChildArchivalObjectURIs(children []ResourceTree, aos *[]string) { +// for _, child := range children { +// *aos = append(*aos, child.RecordURI) +// if child.HasChildren { +// getChildArchivalObjectURIs(child.Children, aos) +// } +// } +// } func (a ASClient) DeleteArchivalObject(repositoryID int, archivalObjectID int) (string, error) { responseMessage := "" @@ -119,18 +117,18 @@ func (a ASClient) DeleteArchivalObject(repositoryID int, archivalObjectID int) ( return responseMessage, nil } -func getChildArchivalObjectURIsFiltered(children []ResourceTree, aos *[]string, filter string) { - matcher := regexp.MustCompile(filter) - for _, child := range children { - if matcher.MatchString(strings.Join(child.InstanceTypes, " ")) == true { - *aos = append(*aos, child.RecordURI) - } - - if child.HasChildren { - getChildArchivalObjectURIs(child.Children, aos) - } - } -} +// func getChildArchivalObjectURIsFiltered(children []ResourceTree, aos *[]string, filter string) { +// matcher := regexp.MustCompile(filter) +// for _, child := range children { +// if matcher.MatchString(strings.Join(child.InstanceTypes, " ")) == true { +// *aos = append(*aos, child.RecordURI) +// } + +// if child.HasChildren { +// getChildArchivalObjectURIs(child.Children, aos) +// } +// } +// } func (a *ASClient) GetRandomArchivalObject(repositoryID int, resourceID int) (int, int, error) { diff --git a/CHANGELOG.md b/CHANGELOG.md index 321d7c5..092d622 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,22 @@ ## CHANGELOG +#### v0.7.1 + - remove debug print from `NewClientFromCreds()` + - tidy go mod files (removed unused libxml2 package) + - tweak range statement per linter recommendation + - add missing error check + - comment out unused code + - add error check to (a *ADClient)GetAgent() + - update CHANGELOG, bump to v0.7.1 + #### v0.7.0 - - add `func (a *ASClient) FindArchivalObjectsByID(...)([]string, error)` + - add `func (a *ASClient) FindArchivalObjectsByID(...)([]string, error)` that allows you to look up archival objects by the `ref_id` or `component_id` fields - + #### v0.6.1 - bug fix: rewrite `func (wor WorkOrderRow) String()` to use `encoding/csv` to handle string escapes - + #### v0.6.0 - add `...FromURI()` functions: - add `GetArchivalObjectFromURI()` @@ -24,5 +33,3 @@ - force `bool` key/value pairs to always be sent in marshaled JSON for selected types - remove `omitempty` option from `DigitalObject` type `bool` JSON tags - remove `omitempty` option from `FileVersion` type `bool` JSON tags - - diff --git a/Common.go b/Common.go index c25bfc6..07deffb 100644 --- a/Common.go +++ b/Common.go @@ -11,7 +11,7 @@ import ( "time" ) -var LibraryVersion = "v0.7.0" +var LibraryVersion = "v0.7.1" var seed = rand.NewSource(time.Now().UnixNano()) var rGen = rand.New(seed) @@ -105,15 +105,15 @@ func (a *ASClient) PostEndpoint(endpoint string, requestBody string, authenticat return response, nil } -// slice contains methods -func containsInt(list []int, id int) bool { - for _, i := range list { - if id == i { - return true - } - } - return false -} +// // slice contains methods +// func containsInt(list []int, id int) bool { +// for _, i := range list { +// if id == i { +// return true +// } +// } +// return false +// } type CreateOrUpdateResponse struct { Status string `json:"status"` diff --git a/Repositories.go b/Repositories.go index 8031e56..850529a 100644 --- a/Repositories.go +++ b/Repositories.go @@ -22,6 +22,9 @@ func (a *ASClient) GetRepositories() ([]int, error) { reps := make([]map[string]interface{}, 1, 1) err = json.Unmarshal(body, &reps) + if err != nil { + return repIds, err + } for i := range reps { rep := fmt.Sprintf("%v", reps[i]["uri"]) diff --git a/Schema_test.go b/Schema_test.go index 1d0a508..3422e28 100644 --- a/Schema_test.go +++ b/Schema_test.go @@ -2,8 +2,9 @@ package aspace import ( "flag" - goaspacetest "github.com/nyudlts/go-aspace/goaspace_testing" "testing" + + goaspacetest "github.com/nyudlts/go-aspace/goaspace_testing" ) func TestSchemas(t *testing.T) { @@ -27,7 +28,7 @@ func TestSchemas(t *testing.T) { t.Log("Successfully got a list of schemas") keys := make([]string, 0, len(schemas)) - for k, _ := range schemas { + for k := range schemas { keys = append(keys, k) } diff --git a/go.mod b/go.mod index c4a550c..38eaa1e 100644 --- a/go.mod +++ b/go.mod @@ -2,9 +2,4 @@ module github.com/nyudlts/go-aspace go 1.21 -require ( - github.com/lestrrat-go/libxml2 v0.0.0-20231124114421-99c71026c2f5 - gopkg.in/yaml.v2 v2.3.0 -) - -require github.com/pkg/errors v0.9.1 // indirect +require gopkg.in/yaml.v2 v2.3.0 diff --git a/go.sum b/go.sum index 094222e..168980d 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,3 @@ -github.com/lestrrat-go/libxml2 v0.0.0-20231124114421-99c71026c2f5 h1:lR4DHv41vdkhNPNDlr56n8BuLINQeWNeQAaAzBEOcuw= -github.com/lestrrat-go/libxml2 v0.0.0-20231124114421-99c71026c2f5/go.mod h1:/0MMipmS+5SMXCSkulsvJwYmddKI4IL5tVy6AZMo9n0= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=