Skip to content

Commit

Permalink
fix: add comments for const definition
Browse files Browse the repository at this point in the history
issue: #128
  • Loading branch information
CodeBear801 committed Jan 13, 2020
1 parent ec7ad8d commit d416d67
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package options

// Query parameter for oasis service
// https://github.com/Telenav/osrm-backend/issues/128
const (
KeyMaxRange = "max_range"
KeyCurrRange = "curr_range"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package genericoptions
package options

// Default configuration for oasis service
const (
InvalidMaxRangeValue = -1.0 // default
InvalidCurrentRangeValue = -1.0 // default
Expand Down
18 changes: 6 additions & 12 deletions integration/pkg/api/oasis/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ package oasis
import (
"errors"
"fmt"
"math"
"net/url"
"strconv"
"strings"

"github.com/Telenav/osrm-backend/integration/pkg/api"
"github.com/Telenav/osrm-backend/integration/pkg/api/oasis/genericoptions"
"github.com/Telenav/osrm-backend/integration/pkg/api/oasis/options"
"github.com/Telenav/osrm-backend/integration/pkg/api/osrm/coordinate"
"github.com/golang/glog"
Expand Down Expand Up @@ -38,10 +36,10 @@ func NewRequest() *Request {
Coordinates: coordinate.Coordinates{},

// generic options
MaxRange: genericoptions.InvalidMaxRangeValue,
CurrRange: genericoptions.InvalidCurrentRangeValue,
PreferLevel: genericoptions.DefaultPreferLevel,
SafeLevel: genericoptions.DefaultSafeLevel,
MaxRange: options.InvalidMaxRangeValue,
CurrRange: options.InvalidCurrentRangeValue,
PreferLevel: options.DefaultPreferLevel,
SafeLevel: options.DefaultSafeLevel,
}
}

Expand Down Expand Up @@ -127,12 +125,12 @@ func (r *Request) parseQuery(params url.Values) error {

func (r *Request) validate() error {
// MaxRange must be set
if floatEquals(r.MaxRange, genericoptions.InvalidMaxRangeValue) || isFloatNegative(r.MaxRange) {
if floatEquals(r.MaxRange, options.InvalidMaxRangeValue) || r.MaxRange < 0 {
return errors.New("Invalid value for " + options.KeyMaxRange + ".")
}

// CurrRange must be set
if floatEquals(r.CurrRange, genericoptions.InvalidCurrentRangeValue) || isFloatNegative(r.CurrRange) {
if floatEquals(r.CurrRange, options.InvalidCurrentRangeValue) || r.CurrRange < 0 {
return errors.New("Invalid value for " + options.KeyCurrRange + ".")
}

Expand Down Expand Up @@ -163,10 +161,6 @@ func floatEquals(a, b float64) bool {
return false
}

func isFloatNegative(a float64) bool {
return !floatEquals(math.Abs(a), a)
}

// RequestURI convert RouteRequest to RequestURI (e.g. "/path?foo=bar").
// see more in https://golang.org/pkg/net/url/#URL.RequestURI
func (r *Request) RequestURI() string {
Expand Down

0 comments on commit d416d67

Please sign in to comment.