instance.go 737 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package kos
  2. import (
  3. "git.nspix.com/golang/kos/entry/cli"
  4. "git.nspix.com/golang/kos/entry/http"
  5. _ "git.nspix.com/golang/kos/util/fetch"
  6. _ "git.nspix.com/golang/kos/util/random"
  7. _ "git.nspix.com/golang/kos/util/reflection"
  8. "sync"
  9. )
  10. var (
  11. once sync.Once
  12. std *application
  13. )
  14. func initApplication(cbs ...Option) {
  15. once.Do(func() {
  16. std = New(cbs...)
  17. })
  18. }
  19. func Init(cbs ...Option) *application {
  20. initApplication(cbs...)
  21. return std
  22. }
  23. func Node() *Info {
  24. initApplication()
  25. return std.Info()
  26. }
  27. func Http() *http.Server {
  28. initApplication()
  29. return std.Http()
  30. }
  31. func Command() *cli.Server {
  32. initApplication()
  33. return std.Command()
  34. }
  35. func Handle(method string, cb HandleFunc) {
  36. initApplication()
  37. std.Handle(method, cb)
  38. }