http urls monitor.

raw.go 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright (c) 2012-present The upper.io/db authors. All rights reserved.
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining
  4. // a copy of this software and associated documentation files (the
  5. // "Software"), to deal in the Software without restriction, including
  6. // without limitation the rights to use, copy, modify, merge, publish,
  7. // distribute, sublicense, and/or sell copies of the Software, and to
  8. // permit persons to whom the Software is furnished to do so, subject to
  9. // the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be
  12. // included in all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  18. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  19. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  20. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. package db
  22. import (
  23. "fmt"
  24. )
  25. // RawValue interface represents values that can bypass SQL filters. This is an
  26. // exported interface but it's rarely used directly, you may want to use
  27. // the `db.Raw()` function instead.
  28. type RawValue interface {
  29. fmt.Stringer
  30. Compound
  31. // Raw returns the string representation of the value that the user wants to
  32. // pass without any escaping.
  33. Raw() string
  34. // Arguments returns the arguments to be replaced on the query.
  35. Arguments() []interface{}
  36. }
  37. type rawValue struct {
  38. v string
  39. a *[]interface{} // This may look ugly but allows us to use db.Raw() as keys for db.Cond{}.
  40. }
  41. func (r rawValue) Arguments() []interface{} {
  42. if r.a != nil {
  43. return *r.a
  44. }
  45. return nil
  46. }
  47. func (r rawValue) Raw() string {
  48. return r.v
  49. }
  50. func (r rawValue) String() string {
  51. return r.Raw()
  52. }
  53. // Sentences return each one of the map records as a compound.
  54. func (r rawValue) Sentences() []Compound {
  55. return []Compound{r}
  56. }
  57. // Operator returns the default compound operator.
  58. func (r rawValue) Operator() CompoundOperator {
  59. return OperatorNone
  60. }
  61. // Empty return false if this struct holds no value.
  62. func (r rawValue) Empty() bool {
  63. return r.v == ""
  64. }
  65. // Raw marks chunks of data as protected, so they pass directly to the query
  66. // without any filtering. Use with care.
  67. //
  68. // Example:
  69. //
  70. // // SOUNDEX('Hello')
  71. // Raw("SOUNDEX('Hello')")
  72. //
  73. // Raw returns a value that satifies the db.RawValue interface.
  74. func Raw(value string, args ...interface{}) RawValue {
  75. r := rawValue{v: value, a: nil}
  76. if len(args) > 0 {
  77. r.a = &args
  78. }
  79. return r
  80. }
  81. var _ RawValue = &rawValue{}