english русский
Simple and amazing. Templates for any folder!
Because why not? Yes, this package is really small, but why not to have yet another universal package?
Path templates using every where: in openapi, mux router, and many other projects! So, why not to create unified, production-ready and just damn simple implementation?
Am i required to say how to install? Okay, okay...
go get -u -v github.com/quenbyako/path-template
God bless a guy, who invent so simple package fetching.
Code examples are here
So, the main architecture of all package has two amazing functions: FillTemplate
and MatchPath
. First one is, well, fills your template with your variables, and second one, guess what? You goddamn right, matching input path with template, and, if matched, extracting variables. Note that MatchPath
does not have wildcards, and if you try to match /a/b/c
into template /{long_path}/c
, MatchPath
will throw error that path doesn't matched with template.
Here is a good example:
package main
import "github.com/quenbyako/path-template"
func main() {
res, err := tpl.FillTemplate(
"/home/vasya/{project_path}/assets",
map[string]string{
"project_path":"go/src/gihub.com/xelaj/telegram_client",
},
)
check(err)
println(res)
// will print: "/home/vasya/go/src/gihub.com/xelaj/telegram_client/assets"
}
Is it? Well, no, it's partly compliant. But main components (variables, regex, and shiny mustache brackets {}
) of this specification is implemented already. And, as always, PRs are really welcome! I want to improve path-template
as 6570 implementation.
Wanna full compliancy? Use package like this one, maybe it'll help you. But note, that this one was committed last time 5 (!!!) years ago.
Please read contributing guide if you want to help. And the help is very necessary!
- idk, add some tests?
- Richard Cooper <[email protected]>
This project is licensed under the MIT License - see the LICENSE file for details