-
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.
Added missing types and their validation
- Loading branch information
1 parent
9bc06c0
commit 90de0c8
Showing
11 changed files
with
1,058 additions
and
54 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
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 cff | ||
|
||
import ( | ||
"regexp" | ||
) | ||
|
||
var regexISBN *regexp.Regexp | ||
|
||
func init() { | ||
regexISBN = regexp.MustCompile(`^[0-9\- ]{10,17}X?$`) | ||
} | ||
|
||
//UnmarshalYAML parses a cff string into an ISBN object | ||
func (j *ISBN) UnmarshalYAML(unmarshal func(interface{}) error) error { | ||
return CommonUnmarshalYAML( | ||
func(cffString string) { | ||
*j = ISBN(cffString) | ||
}, | ||
regexISBN, | ||
unmarshal, | ||
"ISBN", | ||
) | ||
} | ||
|
||
//MarshalYAML serializes an ISBN object into a cff string | ||
func (j ISBN) MarshalYAML() (interface{}, error) { | ||
return CommonMarshalYAML(string(j), regexISBN, "ISBN") | ||
} |
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 cff | ||
|
||
import ( | ||
"regexp" | ||
) | ||
|
||
var regexISSN *regexp.Regexp | ||
|
||
func init() { | ||
regexISSN = regexp.MustCompile(`^\d{4}-\d{3}[\dxX]$`) | ||
} | ||
|
||
//UnmarshalYAML parses a cff string into an ISSN object | ||
func (j *ISSN) UnmarshalYAML(unmarshal func(interface{}) error) error { | ||
return CommonUnmarshalYAML( | ||
func(cffString string) { | ||
*j = ISSN(cffString) | ||
}, | ||
regexISSN, | ||
unmarshal, | ||
"ISSN", | ||
) | ||
} | ||
|
||
//MarshalYAML serializes an ISSN object into a cff string | ||
func (j ISSN) MarshalYAML() (interface{}, error) { | ||
return CommonMarshalYAML(string(j), regexISSN, "ISSN") | ||
} |
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 cff | ||
|
||
import ( | ||
"regexp" | ||
) | ||
|
||
var regexLanguage *regexp.Regexp | ||
|
||
func init() { | ||
regexLanguage = regexp.MustCompile(`^[a-z]{2,3}$`) | ||
} | ||
|
||
//UnmarshalYAML parses a cff string into a Language object | ||
func (j *Language) UnmarshalYAML(unmarshal func(interface{}) error) error { | ||
return CommonUnmarshalYAML( | ||
func(cffString string) { | ||
*j = Language(cffString) | ||
}, | ||
regexLanguage, | ||
unmarshal, | ||
"language", | ||
) | ||
} | ||
|
||
//MarshalYAML serializes a Language object into a cff string | ||
func (j Language) MarshalYAML() (interface{}, error) { | ||
return CommonMarshalYAML(string(j), regexLanguage, "language") | ||
} |
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 cff | ||
|
||
import ( | ||
"regexp" | ||
) | ||
|
||
var regexORCID *regexp.Regexp | ||
|
||
func init() { | ||
regexORCID = regexp.MustCompile(`https://orcid\.org/[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{3}[0-9X]{1}`) | ||
} | ||
|
||
//UnmarshalYAML parses a cff string into an ORCID object | ||
func (j *ORCID) UnmarshalYAML(unmarshal func(interface{}) error) error { | ||
return CommonUnmarshalYAML( | ||
func(cffString string) { | ||
*j = ORCID(cffString) | ||
}, | ||
regexORCID, | ||
unmarshal, | ||
"ORCID", | ||
) | ||
} | ||
|
||
//MarshalYAML serializes an ORCID object into a cff string | ||
func (j ORCID) MarshalYAML() (interface{}, error) { | ||
return CommonMarshalYAML(string(j), regexORCID, "ORCID") | ||
} |
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 cff | ||
|
||
import ( | ||
"regexp" | ||
) | ||
|
||
var regexPMCID *regexp.Regexp | ||
|
||
func init() { | ||
regexPMCID = regexp.MustCompile(`^PMC[0-9]{7}$`) | ||
} | ||
|
||
//UnmarshalYAML parses a cff string into a PMCID object | ||
func (j *PMCID) UnmarshalYAML(unmarshal func(interface{}) error) error { | ||
return CommonUnmarshalYAML( | ||
func(cffString string) { | ||
*j = PMCID(cffString) | ||
}, | ||
regexPMCID, | ||
unmarshal, | ||
"PMC ID", | ||
) | ||
} | ||
|
||
//MarshalYAML serializes a PMCID object into a cff string | ||
func (j PMCID) MarshalYAML() (interface{}, error) { | ||
return CommonMarshalYAML(string(j), regexPMCID, "PMC ID") | ||
} |
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 cff | ||
|
||
import ( | ||
"regexp" | ||
) | ||
|
||
var regexSWHID *regexp.Regexp | ||
|
||
func init() { | ||
regexSWHID = regexp.MustCompile(`^swh:1:(snp|rel|rev|dir|cnt):[0-9a-fA-F]{40}$`) | ||
} | ||
|
||
//UnmarshalYAML parses a cff string into a SWHID object | ||
func (j *SWHID) UnmarshalYAML(unmarshal func(interface{}) error) error { | ||
return CommonUnmarshalYAML( | ||
func(cffString string) { | ||
*j = SWHID(cffString) | ||
}, | ||
regexSWHID, | ||
unmarshal, | ||
"SWH Identifier", | ||
) | ||
} | ||
|
||
//MarshalYAML serializes a SWHID object into a cff string | ||
func (j SWHID) MarshalYAML() (interface{}, error) { | ||
return CommonMarshalYAML(string(j), regexSWHID, "SWH Identifier") | ||
} |
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
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,30 @@ | ||
package cff | ||
|
||
import ( | ||
"errors" | ||
"regexp" | ||
) | ||
|
||
func CommonMarshalYAML(cffString string, regexPattern *regexp.Regexp, typeOfString string) (interface{}, error) { | ||
var err error | ||
if regexPattern.MatchString(cffString) { | ||
return cffString, err | ||
} else { | ||
return "", errors.New("invalid " + typeOfString + ": " + cffString) | ||
} | ||
} | ||
|
||
func CommonUnmarshalYAML(matchAction func(string), regexPattern *regexp.Regexp, unmarshal func(interface{}) error, typeOfString string) error { | ||
var cffString string | ||
err := unmarshal(&cffString) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if regexPattern.MatchString(cffString) { | ||
matchAction(cffString) | ||
} else { | ||
err = errors.New("invalid " + typeOfString + ": " + cffString) | ||
} | ||
return err | ||
} |
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
Oops, something went wrong.