Documentation ¶
Overview ¶
Package qvalue is a parser for [quality values](https://developer.mozilla.org/en-US/docs/Glossary/Quality_values).
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // Error to indicate there is invalid quality in provided string QualityParseError = errors.New("Quality is not a valid number") // Error io indicate a quality is out of range QualityRangeError = errors.New("Quality should be in range of [0.0, 1.0]") )
Functions ¶
Types ¶
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options is configure for this parser.
func NewOptions ¶
func NewOptions() *Options
Create a new default parser option. The default behavior is report any error and default quality is 1.0.
func (*Options) IgnoreQualityParseError ¶
IgnoreQualityParseError makes this parse option ignore `QualityParseError`, and set the item's quality to `value` if this error happened.
func (*Options) IgnoreQualityRangeError ¶
IgnoreQualityParseError makes this parse option ignore `QualityRangeError` and set the item's quality to `value` if this error happened.
func (*Options) Parse ¶
Parse a quality value series.
Example ¶
package main import ( "fmt" "github.com/7sDream/qvalue" ) func main() { o := qvalue.NewOptions() qvs, _ := o.Parse("gzip, deflate;q=0.8, br;q=0.7, identity;q=0.5, *;q=0.1") for _, qv := range qvs { fmt.Printf("%s: %d\n", qv.Value, qv.Quality) } }
Output: gzip: 1000 deflate: 800 br: 700 identity: 500 *: 100
func (*Options) ParseAndSort ¶
Parse a quality value series, and sort items according to their quality.
func (*Options) SetDefaultQuality ¶
SetDefaultQuality set the default quality if a item do not have it. The default is 1.0, according to the spec.