Skip to content

quenbyako/path-template

Repository files navigation

path-template

help wanted godoc reference Go Report Card license MIT version v1.0.0 unstable chat telegram

english русский

Simple and amazing. Templates for any folder!

Oh my god, why???

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?

Getting started

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.

How to use

demo

Code examples are here

Make your first path checker

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"
}

RFC6570-compliant?

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.

Contributing

Please read contributing guide if you want to help. And the help is very necessary!

TODO

  • idk, add some tests?

Authors

License

This project is licensed under the MIT License - see the LICENSE file for details

About

Templates for any folder!

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages