Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to/from URI type generator #8

Open
alexec opened this issue Oct 26, 2020 · 0 comments
Open

to/from URI type generator #8

alexec opened this issue Oct 26, 2020 · 0 comments

Comments

@alexec
Copy link

alexec commented Oct 26, 2020

I'd like to create a type generator that takes a type like this:

// url:"prefix:s3"
type S3 struct {
   Endpoint string `url:"host"`
   Bucket string `url:"path[0]"`
   Key string `url:"path[1]"`
}
// url:"prefix:gcs"
type GCS struct {
   Endpoint string `url:"host"`
   Bucket string `url:"path[0]"`
   Key string `url:"path[1]"`
}

And this would generate the following funcs:

func (x S3) String() string {
   return "s3://" + x.Endpoint + "/" + x.Bucket + "/" + x.Key
}
func ParseS3(x string) (S3,error) {
u, err:=url.Parse(
if err!=nil {return err}
parts:=strings.Split(u.Path)
return S3{Endpoint: u.Host, Bucket: parts[0], Key: parts[1]}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant