自定义组件

file system
App (root)
├─ main.go
├─ app.yml
└─ components
   └─ my
      └─ my.go
my.go
package my

type Instance struct {
   Message string `yaml:"message"`
}

const name = "my"

var instance *Instance

func (i *Instance) Run() error {
   instance = i
   return nil
}

func (i *Instance) GetName() string {
   return name
}

func Get() *Instance {
   return instance
}
app.yml
my:
  message: my name is langgo
main.go
package main

import (
   "fmt"
   "github.com/langwan/langgo"
   "langwan/langgo-examples/Advanced/Custom-Components/components/my"
)

func main() {
   langgo.Run(&my.Instance{})
   fmt.Println(my.Get().Message)
}

Last updated