浏览代码

Initial commit

Alexey Kim 1 年之前
当前提交
c5e9eec8b6
共有 3 个文件被更改,包括 32 次插入0 次删除
  1. 1 0
      .gitignore
  2. 28 0
      config/config.go
  3. 3 0
      go.mod

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+.idea

+ 28 - 0
config/config.go

@@ -0,0 +1,28 @@
+package config
+
+import "reflect"
+
+type IConfig interface {
+	Invalidate() error
+}
+
+func Invalidate(config IConfig) error {
+	if config == nil || reflect.ValueOf(config).IsZero() {
+		return nil
+	}
+
+	r := reflect.ValueOf(config).Elem()
+	for i := 0; i < r.NumField(); i++ {
+		if !r.Field(i).CanInterface() || r.Field(i).IsZero() {
+			continue
+		}
+
+		if elm, ok := r.Field(i).Interface().(IConfig); ok {
+			if er := elm.Invalidate(); er != nil {
+				return er
+			}
+		}
+	}
+
+	return nil
+}

+ 3 - 0
go.mod

@@ -0,0 +1,3 @@
+module beejay.kim/craft/api
+
+go 1.20