本文整理匯總了Golang中github.com/pierrre/imageserver.Params.GetString方法的典型用法代碼示例。如果您正苦於以下問題:Golang Params.GetString方法的具體用法?Golang Params.GetString怎麽用?Golang Params.GetString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/pierrre/imageserver.Params
的用法示例。
在下文中一共展示了Params.GetString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: buildArgumentsGravity
func (server *Server) buildArgumentsGravity(arguments *list.List, params imageserver.Params) error {
gravity, _ := params.GetString("gravity")
var translatedGravity string
if gravity != "" {
switch {
case gravity == "n":
translatedGravity = "North"
case gravity == "s":
translatedGravity = "South"
case gravity == "e":
translatedGravity = "East"
case gravity == "w":
translatedGravity = "West"
case gravity == "ne":
translatedGravity = "NorthEast"
case gravity == "se":
translatedGravity = "SouthEast"
case gravity == "nw":
translatedGravity = "NorthWest"
case gravity == "sw":
translatedGravity = "SouthWest"
}
if translatedGravity == "" {
return &imageserver.ParamError{Param: "gravity", Message: "gravity should n, s, e, w, ne, se, nw or sw"}
}
} else {
// Default gravity is center.
translatedGravity = "Center"
}
arguments.PushBack("-gravity")
arguments.PushBack(fmt.Sprintf("%s", translatedGravity))
return nil
}
示例2: buildArgumentsCrop
func (server *Server) buildArgumentsCrop(arguments *list.List, params imageserver.Params) error {
if !params.Has("crop") {
return nil
}
crop, _ := params.GetString("crop")
cropArgs := strings.Split(crop, ",")
cropArgsLen := len(cropArgs)
if cropArgsLen != 2 && cropArgsLen != 4 {
return &imageserver.ParamError{Param: "crop", Message: "Invalid crop request, parameters number mismatch"}
}
if cropArgsLen == 2 {
width, _ := strconv.Atoi(cropArgs[0])
height, _ := strconv.Atoi(cropArgs[1])
arguments.PushBack("-crop")
arguments.PushBack(fmt.Sprintf("%dx%d", width, height))
arguments.PushBack("+repage")
}
if cropArgsLen == 4 {
width, _ := strconv.Atoi(cropArgs[0])
height, _ := strconv.Atoi(cropArgs[1])
x, _ := strconv.Atoi(cropArgs[2])
y, _ := strconv.Atoi(cropArgs[3])
arguments.PushBack("-crop")
arguments.PushBack(fmt.Sprintf("%dx%d+%d+%d", width, height, x, y))
arguments.PushBack("+repage")
}
return nil
}
示例3: getResampling
func (prc *ResizeProcessor) getResampling(params imageserver.Params) (gift.Resampling, error) {
if !params.Has("resampling") {
if prc.DefaultResampling != nil {
return prc.DefaultResampling, nil
}
return gift.NearestNeighborResampling, nil
}
rsp, err := params.GetString("resampling")
if err != nil {
return nil, err
}
switch rsp {
case "nearest_neighbor":
return gift.NearestNeighborResampling, nil
case "box":
return gift.BoxResampling, nil
case "linear":
return gift.LinearResampling, nil
case "cubic":
return gift.CubicResampling, nil
case "lanczos":
return gift.LanczosResampling, nil
}
return nil, &imageserver.ParamError{Param: "resampling", Message: "invalid value"}
}
示例4: getInterpolation
func (prc *Processor) getInterpolation(params imageserver.Params) (resize.InterpolationFunction, error) {
if !params.Has("interpolation") {
return prc.DefaultInterpolation, nil
}
interpolation, err := params.GetString("interpolation")
if err != nil {
return 0, err
}
switch interpolation {
case "nearest_neighbor":
return resize.NearestNeighbor, nil
case "bilinear":
return resize.Bilinear, nil
case "bicubic":
return resize.Bicubic, nil
case "mitchell_netravali":
return resize.MitchellNetravali, nil
case "lanczos2":
return resize.Lanczos2, nil
case "lanczos3":
return resize.Lanczos3, nil
default:
return 0, &imageserver.ParamError{Param: "interpolation", Message: "invalid value"}
}
}
示例5: getPath
func (srv *Server) getPath(params imageserver.Params) (string, error) {
src, err := params.GetString(imageserver_source.Param)
if err != nil {
return "", err
}
// This trick comes from net/http.Dir.Open().
// It allows to "jail" the path inside the root.
return filepath.Join(srv.Root, filepath.FromSlash(path.Clean("/"+src))), nil
}
示例6: getBackground
func (prc *RotateProcessor) getBackground(params imageserver.Params) (color.Color, error) {
if !params.Has("background") {
return color.Transparent, nil
}
s, err := params.GetString("background")
if err != nil {
return nil, err
}
c, err := parseHexColor(s)
if err != nil {
return nil, &imageserver.ParamError{Param: "background", Message: err.Error()}
}
return c, nil
}
示例7: TestParseQueryString
func TestParseQueryString(t *testing.T) {
req, err := http.NewRequest("GET", "http://localhost?string=foo", nil)
if err != nil {
t.Fatal(err)
}
params := imageserver.Params{}
ParseQueryString("string", req, params)
s, err := params.GetString("string")
if err != nil {
t.Fatal(err)
}
if s != "foo" {
t.Fatal("not equals")
}
}
示例8: Parse
// Parse implements Parser.
func (parser *FormatParser) Parse(req *http.Request, params imageserver.Params) error {
ParseQueryString("format", req, params)
if !params.Has("format") {
return nil
}
format, err := params.GetString("format")
if err != nil {
return err
}
if format == "jpg" {
format = "jpeg"
}
params.Set("format", format)
return nil
}
示例9: parseSourceTransform
func parseSourceTransform(ps Parser, req *http.Request, params imageserver.Params, f func(string) string) error {
err := ps.Parse(req, params)
if err != nil {
return err
}
if !params.Has(imageserver.SourceParam) {
return nil
}
source, err := params.GetString(imageserver.SourceParam)
if err != nil {
return err
}
source = f(source)
params.Set(imageserver.SourceParam, source)
return nil
}
示例10: getHandler
func (hdr *FallbackHandler) getHandler(im *imageserver.Image, params imageserver.Params) (imageserver.Handler, error) {
if im.Format != "gif" {
return hdr.Fallback, nil
}
if !params.Has("format") {
return hdr.Handler, nil
}
format, err := params.GetString("format")
if err != nil {
return nil, err
}
if format != "gif" {
return hdr.Fallback, nil
}
return hdr.Handler, nil
}
示例11: getModeFunc
func getModeFunc(params imageserver.Params) (modeFunc, error) {
if !params.Has("mode") {
return resize.Resize, nil
}
mode, err := params.GetString("mode")
if err != nil {
return nil, err
}
switch mode {
case "resize":
return resize.Resize, nil
case "thumbnail":
return resize.Thumbnail, nil
default:
return nil, &imageserver.ParamError{Param: "mode", Message: "invalid value"}
}
}
示例12: getInterpolation
func (prc *RotateProcessor) getInterpolation(params imageserver.Params) (gift.Interpolation, error) {
if !params.Has("interpolation") {
return prc.DefaultInterpolation, nil
}
interp, err := params.GetString("interpolation")
if err != nil {
return 0, err
}
switch interp {
case "nearest_neighbor":
return gift.NearestNeighborInterpolation, nil
case "linear":
return gift.LinearInterpolation, nil
case "cubic":
return gift.CubicInterpolation, nil
}
return 0, &imageserver.ParamError{Param: "interpolation", Message: "invalid value"}
}
示例13: TestFormatParserParse
func TestFormatParserParse(t *testing.T) {
parser := &FormatParser{}
req, err := http.NewRequest("GET", "http://localhost?format=jpg", nil)
if err != nil {
t.Fatal(err)
}
params := imageserver.Params{}
err = parser.Parse(req, params)
if err != nil {
t.Fatal(err)
}
format, err := params.GetString("format")
if err != nil {
t.Fatal(err)
}
if format != "jpeg" {
t.Fatal("not equals")
}
}
示例14: TestSourceParserParse
func TestSourceParserParse(t *testing.T) {
parser := &SourceParser{}
req, err := http.NewRequest("GET", "http://localhost?source=foo", nil)
if err != nil {
t.Fatal(err)
}
params := imageserver.Params{}
err = parser.Parse(req, params)
if err != nil {
t.Fatal(err)
}
source, err := params.GetString(imageserver.SourceParam)
if err != nil {
t.Fatal(err)
}
if source != "foo" {
t.Fatal("not equals")
}
}
示例15: doRequest
func (srv *Server) doRequest(params imageserver.Params) (*http.Response, error) {
src, err := params.GetString(imageserver_source.Param)
if err != nil {
return nil, err
}
req, err := http.NewRequest("GET", src, nil)
if err != nil {
return nil, newSourceError(err.Error())
}
c := srv.Client
if c == nil {
c = http.DefaultClient
}
response, err := c.Do(req)
if err != nil {
return nil, newSourceError(err.Error())
}
return response, nil
}