本文整理匯總了Golang中github.com/pierrre/imageserver.Params.Set方法的典型用法代碼示例。如果您正苦於以下問題:Golang Params.Set方法的具體用法?Golang Params.Set怎麽用?Golang Params.Set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/pierrre/imageserver.Params
的用法示例。
在下文中一共展示了Params.Set方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ParseQueryFloat
// ParseQueryFloat takes the param from the query string, parse it as a float64 and add it to params.
func ParseQueryFloat(param string, req *http.Request, params imageserver.Params) error {
s := req.URL.Query().Get(param)
if s == "" {
return nil
}
f, err := strconv.ParseFloat(s, 64)
if err != nil {
return newParseTypeParamError(param, "float", err)
}
params.Set(param, f)
return nil
}
示例2: ParseQueryBool
// ParseQueryBool takes the param from the query string, parse it as an bool and add it to params.
func ParseQueryBool(param string, req *http.Request, params imageserver.Params) error {
s := req.URL.Query().Get(param)
if s == "" {
return nil
}
b, err := strconv.ParseBool(s)
if err != nil {
return newParseTypeParamError(param, "bool", err)
}
params.Set(param, b)
return nil
}
示例3: ParseQueryInt
// ParseQueryInt takes the param from the query string, parse it as an int and add it to params.
func ParseQueryInt(param string, req *http.Request, params imageserver.Params) error {
s := req.URL.Query().Get(param)
if s == "" {
return nil
}
i, err := strconv.Atoi(s)
if err != nil {
return newParseTypeParamError(param, "int", err)
}
params.Set(param, i)
return nil
}
示例4: Parse
// Parse implements Parser.
func (parser *Parser) Parse(req *http.Request, params imageserver.Params) error {
p := imageserver.Params{}
err := parse(req, p)
if err != nil {
if err, ok := err.(*imageserver.ParamError); ok {
err.Param = Param + "." + err.Param
}
return err
}
if !p.Empty() {
params.Set(Param, p)
}
return nil
}
示例5: 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
}
示例6: 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
}
示例7: benchmark
func benchmark(b *testing.B, im *imageserver.Image, params imageserver.Params) {
nim, err := imageserver_image.Decode(im)
if err != nil {
b.Fatal(err)
}
params.Set("width", 100)
params = imageserver.Params{
Param: params,
}
proc := &Processor{}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := proc.Process(nim, params)
if err != nil {
b.Fatal(err)
}
}
}
示例8: benchmarkResizeProcessor
func benchmarkResizeProcessor(b *testing.B, name string, im *imageserver.Image, params imageserver.Params) {
nim, err := imageserver_image.Decode(im)
if err != nil {
b.Fatal(err)
}
params.Set("width", 100)
params = imageserver.Params{
resizeParam: params,
}
prc := &ResizeProcessor{}
b.Run(name, func(b *testing.B) {
for i := 0; i < b.N; i++ {
_, err := prc.Process(nim, params)
if err != nil {
b.Fatal(err)
}
}
})
}
示例9: benchmark
func benchmark(b *testing.B, im *imageserver.Image, params imageserver.Params) {
nim, err := imageserver_image.Decode(im)
if err != nil {
b.Fatal(err)
}
params.Set("width", 100)
params = imageserver.Params{
Param: params,
}
proc := &Processor{}
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
_, err := proc.Process(nim, params)
if err != nil {
b.Fatal(err)
}
}
})
}
示例10: Parse
// Parse implements imageserver/http.Parser.
func (prs *Parser) Parse(req *http.Request, params imageserver.Params) error {
crop := req.URL.Query().Get(param)
if crop == "" {
return nil
}
var minX, minY, maxX, maxY int
_, err := fmt.Sscanf(crop, "%d,%d|%d,%d", &minX, &minY, &maxX, &maxY)
if err != nil {
return &imageserver.ParamError{
Param: param,
Message: fmt.Sprintf("expected format '<int>,<int>|<int>,<int>': %s", err),
}
}
params.Set(param, imageserver.Params{
"min_x": minX,
"min_y": minY,
"max_x": maxX,
"max_y": maxY,
})
return nil
}
示例11: ParseQueryString
// ParseQueryString takes the param from the query string and add it to params.
func ParseQueryString(param string, req *http.Request, params imageserver.Params) {
s := req.URL.Query().Get(param)
if s != "" {
params.Set(param, s)
}
}
示例12: Parse
// Parse implements Parser.
func (parser *SourcePathParser) Parse(req *http.Request, params imageserver.Params) error {
if len(req.URL.Path) > 0 {
params.Set(imageserver_source.Param, req.URL.Path)
}
return nil
}