feat(cmd/joj3): log conf file info
This commit is contained in:
		
							parent
							
								
									08cd9d287b
								
							
						
					
					
						commit
						0a28347247
					
				|  | @ -1,7 +1,10 @@ | |||
| package conf | ||||
| 
 | ||||
| import ( | ||||
| 	"crypto/sha256" | ||||
| 	"encoding/hex" | ||||
| 	"fmt" | ||||
| 	"io" | ||||
| 	"log/slog" | ||||
| 	"os" | ||||
| 	"path/filepath" | ||||
|  | @ -195,6 +198,23 @@ func ParseConfFile(path string) (conf *Conf, err error) { | |||
| 	return | ||||
| } | ||||
| 
 | ||||
| func GetSHA256(filePath string) (string, error) { | ||||
| 	// Open the file
 | ||||
| 	file, err := os.Open(filePath) | ||||
| 	if err != nil { | ||||
| 		return "", err | ||||
| 	} | ||||
| 	defer file.Close() | ||||
| 
 | ||||
| 	// Calculate SHA-256
 | ||||
| 	hash := sha256.New() | ||||
| 	if _, err := io.Copy(hash, file); err != nil { | ||||
| 		return "", err | ||||
| 	} | ||||
| 
 | ||||
| 	return hex.EncodeToString(hash.Sum(nil)), nil | ||||
| } | ||||
| 
 | ||||
| func ParseMsg(confRoot, confName, msg, tag string) (confPath, group string, err error) { | ||||
| 	slog.Info("parse msg", "msg", msg) | ||||
| 	conventionalCommit, err := parseConventionalCommit(msg) | ||||
|  |  | |||
|  | @ -52,12 +52,22 @@ func mainImpl() error { | |||
| 		return err | ||||
| 	} | ||||
| 	slog.Info("try to load conf", "path", confPath) | ||||
| 	confStat, err := os.Stat(confPath) | ||||
| 	if err != nil { | ||||
| 		if os.IsNotExist(err) { | ||||
| 			conf.HintValidScopes(confRoot, confName) | ||||
| 		} | ||||
| 		slog.Error("stat conf", "error", err) | ||||
| 		return err | ||||
| 	} | ||||
| 	sha256, err := conf.GetSHA256(confPath) | ||||
| 	if err != nil { | ||||
| 		slog.Error("get sha256", "error", err) | ||||
| 		return err | ||||
| 	} | ||||
| 	confObj, err := conf.ParseConfFile(confPath) | ||||
| 	if err != nil { | ||||
| 		slog.Error("parse conf", "error", err) | ||||
| 		if _, statErr := os.Stat(confPath); os.IsNotExist(statErr) { | ||||
| 			conf.HintValidScopes(confRoot, confName) | ||||
| 		} | ||||
| 		return err | ||||
| 	} | ||||
| 	slog.Debug("conf loaded", "conf", confObj) | ||||
|  | @ -65,6 +75,8 @@ func mainImpl() error { | |||
| 		slog.Error("setup slog", "error", err) | ||||
| 		return err | ||||
| 	} | ||||
| 	slog.Info("conf info", "sha256", sha256, "modTime", confStat.ModTime(), | ||||
| 		"size", confStat.Size()) | ||||
| 	if err := conf.CheckExpire(confObj); err != nil { | ||||
| 		slog.Error("conf check expire", "error", err) | ||||
| 		return err | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user