New 创建 AsterOS 实例
(opts *Options)
| 39 | |
| 40 | // New 创建 AsterOS 实例 |
| 41 | func New(opts *Options) (*AsterOS, error) { |
| 42 | // 使用默认配置 |
| 43 | if opts == nil { |
| 44 | opts = DefaultOptions() |
| 45 | } |
| 46 | |
| 47 | // 验证配置 |
| 48 | if err := opts.Validate(); err != nil { |
| 49 | return nil, err |
| 50 | } |
| 51 | |
| 52 | // 创建上下文 |
| 53 | ctx, cancel := context.WithCancel(context.Background()) |
| 54 | |
| 55 | // 创建 AsterOS |
| 56 | os := &AsterOS{ |
| 57 | pool: opts.Pool, |
| 58 | registry: NewRegistry(), |
| 59 | interfaces: make(map[string]Interface), |
| 60 | opts: opts, |
| 61 | ctx: ctx, |
| 62 | cancel: cancel, |
| 63 | running: false, |
| 64 | } |
| 65 | |
| 66 | // 初始化路由 |
| 67 | os.initRouter() |
| 68 | |
| 69 | return os, nil |
| 70 | } |
| 71 | |
| 72 | // initRouter 初始化路由 |
| 73 | func (os *AsterOS) initRouter() { |