GO与微服务

手撸golang 仿spring ioc/aop 之10 增强1

2021-04-18  本文已影响0人  老罗话编程

手撸golang 仿spring ioc/aop 之10 增强1

缘起

最近阅读 [Spring Boot技术内幕: 架构设计与实现原理] (朱智胜 , 2020.6)
本系列笔记拟采用golang练习之
Talk is cheap, show me the code.

Spring

Spring的主要特性:
1. 控制反转(Inversion of Control, IoC)
2. 面向容器
3. 面向切面(AspectOriented Programming, AOP)

源码gitee地址:
https://gitee.com/ioly/learning.gooop

原文链接:
https://my.oschina.net/ioly

目标

子目标(Day 10)

domain/IClonable.go

克隆(深度拷贝)接口

package domain

type IClonable interface {
    Clone() interface{}
}

domain/StructInfo.go

所有代码模型实现IClonable接口,这里以StructInfo为例。

func (me *StructInfo) Clone() interface{} {
    it := new(StructInfo)
    it.CodeFile = me.CodeFile
    it.LineNO = me.LineNO
    it.Name = me.Name

    it.Fields = make([]*FieldInfo, len(me.Fields))
    for i,v := range me.Fields {
        it.Fields[i] = v.Clone().(*FieldInfo)
        it.Fields[i].Struct = it
    }

    it.Methods = make([]*MethodInfo, len(me.Methods))
    for i,v := range me.Methods {
        it.Methods[i] = v.Clone().(*MethodInfo)
        it.Methods[i].Struct = it
    }

    it.Annotations = make([]*AnnotationInfo, len(me.Annotations))
    for i,v := range me.Annotations {
        it.Annotations[i] = v.Clone().(*AnnotationInfo)
    }

    return it
}

(未完待续)

上一篇下一篇

猜你喜欢

热点阅读