This repository has been archived by the owner on Mar 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
doc.go
66 lines (66 loc) · 1.81 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Package yagm implements a simple regular expression pattern match mux.
//
// Regular Expressions patterns
//
// YagmMux uses regular expressions to match an URL.
// If you're familiar with Django, the patterns match is almost the same.
// If you're not, take a look in the pattern match explanation below.
//
// Remember, the declared order can affect the match. For example, if you place "^/[a-z]+"
// before "^/index" it will never match "^/index", as the regular expression of "^/[a-z]+"
// can match "/index" too.
//
// The route "^/$" will match only
// /
//
// The route "^/files" will match
// /files
// /files/
// /files/myfilename.txt
//
// The route "^/index$" will match
// /index
// and will not match
// /index/
// /index/other
//
// If you use named groups like "^/(?P<name>[a-zA-Z]+)$"
// you can use yagm.Param or yagm.Params function to retrieve the value ot the groups.
//
// Example
//
// YagmMux is very close to http.ServeMux.
// You can replace your actual http.ServeMux by YagmMux without any problem.
//
// package main
//
// import (
// "fmt"
// "net/http"
//
// "github.com/alexandrevicenzi/yagm"
// )
//
// func homeHandler(w http.ResponseWriter, r *http.Request) {
// fmt.Fprint(w, "Hello World!")
// }
//
// func helloHandler(w http.ResponseWriter, r *http.Request) {
// name, ok := yagm.Param(r, "name")
//
// if !ok {
// name = "Unknown"
// }
//
// fmt.Fprintf(w, "Hello %s!", name)
// }
//
// func main() {
// mux := yagm.New()
// mux.HandleFunc("^/$", homeHandler)
// mux.Handle("^/files", http.StripPrefix("/files", http.FileServer(http.Dir("./"))))
// mux.HandleFunc("^/(?P<name>[a-zA-Z]+)$", helloHandler)
// http.ListenAndServe(":8000", mux)
// }
//
package yagm