This repository has been archived by the owner on Oct 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
229 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
package glieflookup | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"time" | ||
|
||
validations "github.com/robfordww/finident" | ||
) | ||
|
||
type GLIEF struct { | ||
Meta struct { | ||
GoldenCopy struct { | ||
PublishDate time.Time `json:"publishDate"` | ||
} `json:"goldenCopy"` | ||
Pagination struct { | ||
CurrentPage int `json:"currentPage"` | ||
PerPage int `json:"perPage"` | ||
From int `json:"from"` | ||
To int `json:"to"` | ||
Total int `json:"total"` | ||
LastPage int `json:"lastPage"` | ||
} `json:"pagination"` | ||
} `json:"meta"` | ||
Links struct { | ||
First string `json:"first"` | ||
Last string `json:"last"` | ||
} `json:"links"` | ||
Data []struct { | ||
Type string `json:"type"` | ||
ID string `json:"id"` | ||
Attributes struct { | ||
Lei string `json:"lei"` | ||
Entity struct { | ||
LegalName struct { | ||
Name string `json:"name"` | ||
Language string `json:"language"` | ||
} `json:"legalName"` | ||
OtherNames []interface{} `json:"otherNames"` | ||
TransliteratedOtherNames []interface{} `json:"transliteratedOtherNames"` | ||
LegalAddress struct { | ||
Language string `json:"language"` | ||
AddressLines []string `json:"addressLines"` | ||
AddressNumber interface{} `json:"addressNumber"` | ||
AddressNumberWithinBuilding interface{} `json:"addressNumberWithinBuilding"` | ||
MailRouting interface{} `json:"mailRouting"` | ||
City string `json:"city"` | ||
Region string `json:"region"` | ||
Country string `json:"country"` | ||
PostalCode string `json:"postalCode"` | ||
} `json:"legalAddress"` | ||
HeadquartersAddress struct { | ||
Language string `json:"language"` | ||
AddressLines []string `json:"addressLines"` | ||
AddressNumber interface{} `json:"addressNumber"` | ||
AddressNumberWithinBuilding interface{} `json:"addressNumberWithinBuilding"` | ||
MailRouting interface{} `json:"mailRouting"` | ||
City string `json:"city"` | ||
Region string `json:"region"` | ||
Country string `json:"country"` | ||
PostalCode string `json:"postalCode"` | ||
} `json:"headquartersAddress"` | ||
RegisteredAt struct { | ||
ID string `json:"id"` | ||
Other interface{} `json:"other"` | ||
} `json:"registeredAt"` | ||
RegisteredAs interface{} `json:"registeredAs"` | ||
Jurisdiction string `json:"jurisdiction"` | ||
Category interface{} `json:"category"` | ||
LegalForm struct { | ||
ID string `json:"id"` | ||
Other string `json:"other"` | ||
} `json:"legalForm"` | ||
AssociatedEntity struct { | ||
Lei interface{} `json:"lei"` | ||
Name interface{} `json:"name"` | ||
} `json:"associatedEntity"` | ||
Status string `json:"status"` | ||
Expiration struct { | ||
Date interface{} `json:"date"` | ||
Reason interface{} `json:"reason"` | ||
} `json:"expiration"` | ||
SuccessorEntity struct { | ||
Lei interface{} `json:"lei"` | ||
Name interface{} `json:"name"` | ||
} `json:"successorEntity"` | ||
OtherAddresses []interface{} `json:"otherAddresses"` | ||
} `json:"entity"` | ||
Registration struct { | ||
InitialRegistrationDate time.Time `json:"initialRegistrationDate"` | ||
LastUpdateDate time.Time `json:"lastUpdateDate"` | ||
Status string `json:"status"` | ||
NextRenewalDate time.Time `json:"nextRenewalDate"` | ||
ManagingLou string `json:"managingLou"` | ||
CorroborationLevel string `json:"corroborationLevel"` | ||
ValidatedAt struct { | ||
ID string `json:"id"` | ||
Other interface{} `json:"other"` | ||
} `json:"validatedAt"` | ||
ValidatedAs interface{} `json:"validatedAs"` | ||
OtherValidationAuthorities []interface{} `json:"otherValidationAuthorities"` | ||
} `json:"registration"` | ||
Bic interface{} `json:"bic"` | ||
} `json:"attributes"` | ||
Relationships struct { | ||
ManagingLou struct { | ||
Links struct { | ||
Related string `json:"related"` | ||
} `json:"links"` | ||
} `json:"managing-lou"` | ||
LeiIssuer struct { | ||
Links struct { | ||
Related string `json:"related"` | ||
} `json:"links"` | ||
} `json:"lei-issuer"` | ||
FieldModifications struct { | ||
Links struct { | ||
Related string `json:"related"` | ||
} `json:"links"` | ||
} `json:"field-modifications"` | ||
DirectParent struct { | ||
Links struct { | ||
ReportingException string `json:"reporting-exception"` | ||
} `json:"links"` | ||
} `json:"direct-parent"` | ||
UltimateParent struct { | ||
Links struct { | ||
ReportingException string `json:"reporting-exception"` | ||
} `json:"links"` | ||
} `json:"ultimate-parent"` | ||
DirectChildren struct { | ||
Links struct { | ||
RelationshipRecords string `json:"relationship-records"` | ||
Related string `json:"related"` | ||
} `json:"links"` | ||
} `json:"direct-children"` | ||
UltimateChildren struct { | ||
Links struct { | ||
RelationshipRecords string `json:"relationship-records"` | ||
Related string `json:"related"` | ||
} `json:"links"` | ||
} `json:"ultimate-children"` | ||
Isins struct { | ||
Links struct { | ||
Related string `json:"related"` | ||
} `json:"links"` | ||
} `json:"isins"` | ||
} `json:"relationships"` | ||
Links struct { | ||
Self string `json:"self"` | ||
} `json:"links"` | ||
} `json:"data"` | ||
} | ||
|
||
var gliefAPIURI = "https://api.gleif.org/api/v1/lei-records?filter[isin]=%v" | ||
|
||
func lookup_LEI(inISIN string) (string, error) { | ||
var e error | ||
|
||
isinOK, err := validations.ValidateISIN(inISIN) | ||
if err == nil { | ||
//log.Printf("%q is Valid %v", inISIN, isinOK) | ||
if isinOK { | ||
uri := fmt.Sprintf(gliefAPIURI, inISIN) | ||
//log.Printf("URI=[%q]", uri) | ||
|
||
resp, err := http.Get(uri) | ||
if err != nil { | ||
fmt.Println("No response from request") | ||
} | ||
defer resp.Body.Close() | ||
body, err := ioutil.ReadAll(resp.Body) // response body is []byte | ||
//fmt.Println(string(body)) | ||
var result GLIEF | ||
if err := json.Unmarshal(body, &result); err != nil { // Parse []byte to go struct pointer | ||
fmt.Println("Can not unmarshal JSON") | ||
} | ||
//fmt.Printf("result: %v\n", result) | ||
//spew.Dump(result) | ||
return result.Data[0].Attributes.Lei, nil | ||
} | ||
} else { | ||
return "", err | ||
} | ||
|
||
return "", e | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package glieflookup | ||
|
||
import ( | ||
"log" | ||
"testing" | ||
) | ||
|
||
func TestGlief(t *testing.T) { | ||
|
||
g, e := lookup_LEI("GB00BL68HJ26") | ||
if e != nil { | ||
log.Println(e.Error()) | ||
} | ||
t.Log(g) | ||
log.Printf("LEI=%q", g) | ||
|
||
} | ||
|
||
func TestGliefFail(t *testing.T) { | ||
|
||
g, e := lookup_LEI("PO00BL68poop") | ||
if e != nil { | ||
log.Println(e.Error()) | ||
} | ||
t.Log(g) | ||
log.Printf("LEI=%q", g) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module github.com/mt1976/gliefLookup | ||
|
||
go 1.17 | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/robfordww/finident v0.1.1 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/robfordww/finident v0.1.1 h1:1whO7toWmDEYT1IFjbPA1IVzy11hjl1iJpgGebKxt3A= | ||
github.com/robfordww/finident v0.1.1/go.mod h1:8pDtYqWSOqXL+6GCpGOWzi5+wYitmaZ8rie1XWzMOlg= |