You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

template.go 2.3 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright © 2023 OpenIM open source community. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package pkg
  15. import "html/template"
  16. func checkTemplate(t string) *template.Template {
  17. return template.Must(template.New("").Parse(t))
  18. }
  19. var hookTemplate = checkTemplate(`
  20. // Copyright © 2023 OpenIM open source community. All rights reserved.
  21. //
  22. // Licensed under the Apache License, Version 2.0 (the "License");
  23. // you may not use this file except in compliance with the License.
  24. // You may obtain a copy of the License at
  25. //
  26. // http://www.apache.org/licenses/LICENSE-2.0
  27. //
  28. // Unless required by applicable law or agreed to in writing, software
  29. // distributed under the License is distributed on an "AS IS" BASIS,
  30. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  31. // See the License for the specific language governing permissions and
  32. // limitations under the License.
  33. package hooks
  34. import (
  35. "fmt"
  36. urltrie "github.com/OpenIMSDK/OpenKF/server/internal/middleware/hooks/url_trie"
  37. "github.com/gin-gonic/gin"
  38. )
  39. var _ urltrie.Hook = (*{{.HookName}})(nil)
  40. func init() {
  41. urltrie.RegisterHook(&{{.HookName}}{})
  42. fmt.Println("RegisterHook", "Register Hook[{{.HookName}}] success...")
  43. }
  44. type {{.HookName}} struct {
  45. urltrie.Hook
  46. }
  47. // Patterns EDIT THIS TO YOUR OWN HOOK PATTERN
  48. func (h {{.HookName}}) Patterns() string {
  49. return "{{.UrlPattern}}"
  50. }
  51. // Priority EDIT THIS TO YOUR OWN HOOK PRIORITY
  52. func (h GlobalHook) Priority() int64 {
  53. return {{.Prority}}
  54. }
  55. // BeforeRun EDIT THIS TO YOUR OWN HOOK BEFORE RUN
  56. func (h {{.HookName}}) BeforeRun(c *gin.Context) {
  57. c.Next()
  58. }
  59. // AfterRun EDIT THIS TO YOUR OWN HOOK AFTER RUN
  60. func (h {{.HookName}}) AfterRun(c *gin.Context) {
  61. c.Next()
  62. }
  63. `)