http urls monitor.

function.go 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. "reflect"
  24. )
  25. // Function interface defines methods for representing database functions.
  26. // This is an exported interface but it's rarely used directly, you may want to
  27. // use the `db.Func()` function instead.
  28. type Function interface {
  29. // Name returns the function name.
  30. Name() string
  31. // Argument returns the function arguments.
  32. Arguments() []interface{}
  33. }
  34. // Func represents a database function and satisfies the db.Function interface.
  35. //
  36. // Examples:
  37. //
  38. // // MOD(29, 9)
  39. // db.Func("MOD", 29, 9)
  40. //
  41. // // CONCAT("foo", "bar")
  42. // db.Func("CONCAT", "foo", "bar")
  43. //
  44. // // NOW()
  45. // db.Func("NOW")
  46. //
  47. // // RTRIM("Hello ")
  48. // db.Func("RTRIM", "Hello ")
  49. func Func(name string, args ...interface{}) Function {
  50. if len(args) == 1 {
  51. if reflect.TypeOf(args[0]).Kind() == reflect.Slice {
  52. iargs := make([]interface{}, len(args))
  53. for i := range args {
  54. iargs[i] = args[i]
  55. }
  56. args = iargs
  57. }
  58. }
  59. return &dbFunc{name: name, args: args}
  60. }
  61. type dbFunc struct {
  62. name string
  63. args []interface{}
  64. }
  65. func (f *dbFunc) Arguments() []interface{} {
  66. return f.args
  67. }
  68. func (f *dbFunc) Name() string {
  69. return f.name
  70. }
  71. var _ Function = &dbFunc{}