instance.go 608 B

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