-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from forrestjgq/flex-http
Flex http service, allow gomark dock to external http server
- Loading branch information
Showing
4 changed files
with
202 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,84 @@ | ||
// Package gmi defines Marker to represent each variable by interface. | ||
package gmi | ||
|
||
import "net/textproto" | ||
|
||
// Marker is an interface to provide variable marking. | ||
type Marker interface { | ||
// Mark a number, the number definition is bound to marker itself. | ||
Mark(n int32) | ||
// Stop this marking. | ||
Cancel() | ||
} | ||
type Route string | ||
|
||
const ( | ||
RouteVars Route = "vars" | ||
RouteDebug Route = "debug" | ||
RouteJs Route = "js" | ||
) | ||
|
||
type Request struct { | ||
Router Route | ||
Params map[string]string | ||
headers map[string]string | ||
} | ||
|
||
func (r *Request) GetParam(key string) string { | ||
if r.Params == nil { | ||
return "" | ||
} | ||
if v, ok := r.Params[key]; ok { | ||
return v | ||
} | ||
return "" | ||
} | ||
func (r *Request) HasParam(key string) bool { | ||
if r.Params == nil { | ||
return false | ||
} | ||
_, ok := r.Params[key] | ||
return ok | ||
} | ||
func (r *Request) GetHeader(key string) string { | ||
if r.headers == nil { | ||
return "" | ||
} | ||
if v, ok := r.headers[textproto.CanonicalMIMEHeaderKey(key)]; ok { | ||
return v | ||
} | ||
return "" | ||
} | ||
func (r *Request) SetHeader(key, value string) { | ||
if r.headers == nil { | ||
r.headers = make(map[string]string) | ||
} | ||
r.headers[textproto.CanonicalMIMEHeaderKey(key)] = value | ||
} | ||
|
||
type Response struct { | ||
Status int | ||
headers map[string]string | ||
Body []byte | ||
} | ||
func (r *Response) SetHeader(key, value string) { | ||
if r.headers == nil { | ||
r.headers = make(map[string]string) | ||
} | ||
r.headers[textproto.CanonicalMIMEHeaderKey(key)] = value | ||
} | ||
func (r *Response) GetHeaders() map[string]string { | ||
if r.headers == nil { | ||
r.headers = make(map[string]string) | ||
} | ||
return r.headers | ||
} | ||
func (r *Response) GetHeader(key string) string { | ||
if r.headers == nil { | ||
return "" | ||
} | ||
if v, ok := r.headers[textproto.CanonicalMIMEHeaderKey(key)]; ok { | ||
return v | ||
} | ||
return "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.