-
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.
Refactor Downloaded and Generated to handle data-driven external SDK
Can either use an external path, an external archive to be compressed, or a http link to a compressed archive, when using the new archetype "SDK/External". Those arguments along other options are specified through module variable exports. Also, Optional[] of serializable values can now be serialized.
- Loading branch information
1 parent
15efdfa
commit 32ab411
Showing
19 changed files
with
672 additions
and
161 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
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
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,105 @@ | ||
package base | ||
|
||
import ( | ||
"net/url" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
/*************************************** | ||
* Serializable Regexp | ||
***************************************/ | ||
|
||
type Regexp struct { | ||
*regexp.Regexp | ||
} | ||
|
||
func NewRegexp(pattern string) Regexp { | ||
return Regexp{regexp.MustCompile(pattern)} | ||
} | ||
func (x Regexp) Valid() bool { return x.Regexp != nil } | ||
func (x *Regexp) Set(in string) (err error) { | ||
x.Regexp, err = regexp.Compile(in) | ||
return | ||
} | ||
func (x *Regexp) MarshalText() ([]byte, error) { | ||
return UnsafeBytesFromString(x.String()), nil | ||
} | ||
func (x *Regexp) UnmarshalText(data []byte) error { | ||
return x.Set(UnsafeStringFromBytes(data)) | ||
} | ||
func (x *Regexp) Serialize(ar Archive) { | ||
if ar.Flags().IsLoading() { | ||
var url string | ||
ar.String(&url) | ||
if err := x.Set(url); err != nil { | ||
ar.OnError(err) | ||
} | ||
} else { | ||
url := x.String() | ||
ar.String(&url) | ||
} | ||
} | ||
func (x Regexp) Concat(patterns ...Regexp) Regexp { | ||
merged := strings.Builder{} | ||
|
||
var n int | ||
if x.Valid() { | ||
n++ | ||
merged.WriteString("(?:") // non-capturing group | ||
merged.WriteString(x.String()) | ||
merged.WriteRune(')') | ||
} else if len(patterns) == 0 { | ||
return Regexp{} // invalid pattern | ||
} | ||
|
||
for _, it := range patterns { | ||
if it.Valid() { | ||
if n > 0 { | ||
merged.WriteRune('|') | ||
} | ||
n++ | ||
merged.WriteString("(?:") // non-capturing group | ||
merged.WriteString(it.String()) | ||
merged.WriteRune(')') | ||
} | ||
} | ||
|
||
if n > 0 { | ||
return Regexp{Regexp: regexp.MustCompile(merged.String())} | ||
} else { | ||
return Regexp{} | ||
} | ||
} | ||
|
||
/*************************************** | ||
* Serializable URL | ||
***************************************/ | ||
|
||
type Url struct { | ||
*url.URL | ||
} | ||
|
||
func (x Url) Valid() bool { return x.URL != nil } | ||
func (x *Url) Set(in string) (err error) { | ||
x.URL, err = url.Parse(in) | ||
return | ||
} | ||
func (x *Url) MarshalText() ([]byte, error) { | ||
return UnsafeBytesFromString(x.String()), nil | ||
} | ||
func (x *Url) UnmarshalText(data []byte) error { | ||
return x.Set(UnsafeStringFromBytes(data)) | ||
} | ||
func (x *Url) Serialize(ar Archive) { | ||
if ar.Flags().IsLoading() { | ||
var url string | ||
ar.String(&url) | ||
if err := x.Set(url); err != nil { | ||
ar.OnError(err) | ||
} | ||
} else { | ||
url := x.String() | ||
ar.String(&url) | ||
} | ||
} |
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
Oops, something went wrong.