项目作者: jacky2478

项目描述 :
Goaxis is a transformation hub for ensuring that components are completely independent and interaction between components is controlled by the scheduling layer.
高级语言: Go
项目地址: git://github.com/jacky2478/goaxis.git
创建时间: 2019-03-25T14:33:29Z
项目社区:https://github.com/jacky2478/goaxis

开源协议:

下载


Goaxis

Goaxis is a component-oriented transformation hub.

Describe

Goaxis follows the idea of high cohesion and low coupling, which can ensure that components are completely independent, the interaction between components is controlled by the scheduling layer, and the scheduling layer is composed of actual concrete business logic. Goaxis only provides basic data acquisition and native data acquisition. Supports synchronous asynchronous mode data request and broadcast, concurrent security.

Installation

  1. go get github.com/jacky2478/goaxis

Example

  1. // fake code
  2. // at the scheduling layer, implement goaxis.ICallback
  3. type workRsp struct{}
  4. func (p *workRsp) Pull(mode string, caller goaxis.ICaller, ds goaxis.IDataSet) error {
  5. switch caller.Format(".") {
  6. case "libweb.Listen":
  7. port := libdb.GetPort()
  8. dv.Output().Set(port)
  9. }
  10. return nil
  11. }
  12. func (p *workRsp) Push(mode string, caller goaxis.ICaller, ds goaxis.IDataSet) error {
  13. switch caller.Format(".") {
  14. case "libweb.RegistVerify":
  15. data := ds.Input().Get().(string)
  16. libdb.IsUserExist(data)
  17. }
  18. return nil
  19. }
  20. // Initialize the IHUB interface for each component
  21. func main() {
  22. tdb = goaxis.Create("libdb", &workRsp{})
  23. tweb = goaxis.Create("libhttp", &workRsp{})
  24. libdb.Init(tdb)
  25. libweb.Init(tweb)
  26. libweb.ServeAndListen()
  27. }
  28. // Synchronization request using the IHub interface
  29. func ServeAndListen()
  30. {
  31. pullData := goaxis.DataSet()
  32. if err := tdb.SyncPull(tdb.Caller("ServeAndListen", "GetPort"), pullData); err == nil {
  33. port := pullData.Output().Get()
  34. }
  35. }
  36. // Asynchronous request using the IHub interface
  37. func HandleLogin()
  38. {
  39. // 1. verify user login
  40. // 2. get offline messages to push
  41. pullData := goaxis.DataSet()
  42. if err := tdb.ASyncPull(tdb.Caller("HandleLogin", "GetOfflineMessages"), pullData); err == nil {
  43. messages := pullData.Output().GetValueByPush()
  44. }
  45. }
  46. // Synchronization broadcast using the IHub interface
  47. func InitDB()
  48. {
  49. pushData := goaxis.DataSet("MySql")
  50. tdb.SyncPush(tdb.Caller("InitDB"), pushData)
  51. mysqlAddr := fmt.Sprintf("%v", pushData.Output().Get())
  52. }
  53. // Asynchronous broadcast using the IHub interface
  54. func WaitReceive()
  55. {
  56. tweb.ASyncPush(tdb.Caller("WaitReceive"), goaxis.DataSet("data from net"))
  57. }

Notes: