Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
0b01489f
Commit
0b01489f
authored
Jul 29, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
templates: Date -> Now, add Replace and Truncate
parent
7a697700
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
3 deletions
+18
-3
middleware/context.go
middleware/context.go
+18
-3
No files found.
middleware/context.go
View file @
0b01489f
...
...
@@ -6,6 +6,7 @@ import (
"net"
"net/http"
"net/url"
"strings"
"text/template"
"time"
)
...
...
@@ -13,7 +14,7 @@ import (
// This file contains the context and functions available for
// use in the templates.
//
context is the context with which
templates are executed.
//
Context is the context with which Caddy
templates are executed.
type
Context
struct
{
Root
http
.
FileSystem
Req
*
http
.
Request
...
...
@@ -48,8 +49,8 @@ func (c Context) Include(filename string) (string, error) {
return
buf
.
String
(),
nil
}
//
Date returns the current timestamp in the specified format
func
(
c
Context
)
Date
(
format
string
)
string
{
//
Now returns the current timestamp in the specified format.
func
(
c
Context
)
Now
(
format
string
)
string
{
return
time
.
Now
()
.
Format
(
format
)
}
...
...
@@ -114,3 +115,17 @@ func (c Context) Method() string {
func
(
c
Context
)
PathMatches
(
pattern
string
)
bool
{
return
Path
(
c
.
Req
.
URL
.
Path
)
.
Matches
(
pattern
)
}
// Truncate truncates the input string to the given length. If
// input is shorter than length, the entire string is returned.
func
(
c
Context
)
Truncate
(
input
string
,
length
int
)
string
{
if
len
(
input
)
>
length
{
return
input
[
:
length
]
}
return
input
}
// Replace replaces instances of find in input with replacement.
func
(
c
Context
)
Replace
(
input
,
find
,
replacement
string
)
string
{
return
strings
.
Replace
(
input
,
find
,
replacement
,
-
1
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment