upd: helper utilities updated
This commit is contained in:
parent
27144056b1
commit
c81c2be366
@ -54,8 +54,6 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"go/module/essential/visible/service/helper/log"
|
||||
"go/module/essential/visible/service/helper/retriever"
|
||||
"go/module/essential/visible/service/helper/status"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -74,8 +72,6 @@ type obrimCipherResponse struct {
|
||||
|
||||
// ObrimCipher executes encryption and decryption workflows.
|
||||
func ObrimCipher(operationType string, config map[string]any) map[string]any {
|
||||
_, _ = retriever.ObrimRetriever, status.ObrimStatus
|
||||
|
||||
log.ObrimLog("INIT", "Cipher operation initialized.")
|
||||
|
||||
if err := obrimCipherValidateType(operationType); err != nil {
|
||||
@ -88,7 +84,7 @@ func ObrimCipher(operationType string, config map[string]any) map[string]any {
|
||||
|
||||
keyValue := config["key"].(string)
|
||||
|
||||
if err := obrimCipherValidateKey(keyValue); err != nil {
|
||||
if err := obrimCipherValidateKey([]byte(keyValue)); err != nil {
|
||||
return obrimCipherBuildResponse(false, "FAILED_INVALID_KEY", nil)
|
||||
}
|
||||
|
||||
|
||||
@ -45,7 +45,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"go/module/essential/visible/service/helper/log"
|
||||
"go/module/essential/visible/service/helper/retriever"
|
||||
"go/module/essential/visible/service/helper/status"
|
||||
)
|
||||
|
||||
@ -57,14 +56,6 @@ func ObrimHash(
|
||||
status.ObrimStatus("INFO", "Hash utility execution started.")
|
||||
log.ObrimLog("INIT", "Hash utility execution started.")
|
||||
|
||||
_, _ = retriever.ObrimRetriever(
|
||||
"json",
|
||||
map[string]any{
|
||||
"resource": "framework/metadata",
|
||||
"path": "name",
|
||||
},
|
||||
)
|
||||
|
||||
if !obrimHashValidateType(hashType) {
|
||||
status.ObrimStatus("ERROR", "Invalid hash type.")
|
||||
log.ObrimLog("ERROR", "Invalid hash type.")
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
| - Use for framework and software logging.
|
||||
| - Writes append-only UTF-8 log entries.
|
||||
| - Preserves existing log content.
|
||||
| - Uses application metadata to determine storage location.
|
||||
| - Uses software metadata to determine storage location.
|
||||
| - Does not implement rotation, retention, archival, or compression.
|
||||
|
|
||||
| Example:
|
||||
@ -51,7 +51,7 @@ import (
|
||||
|
||||
// ObrimLog writes a structured log entry.
|
||||
func ObrimLog(label string, message string) {
|
||||
applicationName := obrimLogApplicationResolve()
|
||||
softwareName := obrimLogSoftwareResolve()
|
||||
|
||||
timestamp := obrimLogTimestampGenerate()
|
||||
|
||||
@ -61,11 +61,11 @@ func ObrimLog(label string, message string) {
|
||||
message,
|
||||
)
|
||||
|
||||
logDirectory := obrimLogDirectoryResolve(applicationName)
|
||||
logDirectory := obrimLogDirectoryResolve(softwareName)
|
||||
|
||||
logFile := obrimLogFileResolve(
|
||||
logDirectory,
|
||||
applicationName,
|
||||
softwareName,
|
||||
)
|
||||
|
||||
if !obrimLogFileEnsure(logDirectory, logFile) {
|
||||
@ -94,47 +94,47 @@ func obrimLogEntryBuild(
|
||||
)
|
||||
}
|
||||
|
||||
// obrimLogApplicationResolve resolves the application name.
|
||||
func obrimLogApplicationResolve() string {
|
||||
// obrimLogSoftwareResolve resolves the software name.
|
||||
func obrimLogSoftwareResolve() string {
|
||||
value := retriever.ObrimRetriever(
|
||||
"json",
|
||||
map[string]any{
|
||||
"resource": "application/metadata",
|
||||
"path": "application.lower",
|
||||
"resource": "software/metadata",
|
||||
"path": "software.lower",
|
||||
},
|
||||
)
|
||||
|
||||
name := strings.TrimSpace(fmt.Sprintf("%v", value))
|
||||
|
||||
if name == "" {
|
||||
return "application"
|
||||
return "software"
|
||||
}
|
||||
|
||||
return name
|
||||
}
|
||||
|
||||
// obrimLogDirectoryResolve resolves platform-specific log directory paths.
|
||||
func obrimLogDirectoryResolve(applicationName string) string {
|
||||
func obrimLogDirectoryResolve(softwareName string) string {
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
return obrimLogDirectoryResolveWindows(applicationName)
|
||||
return obrimLogDirectoryResolveWindows(softwareName)
|
||||
|
||||
case "darwin":
|
||||
return obrimLogDirectoryResolveMacOS(applicationName)
|
||||
return obrimLogDirectoryResolveMacOS(softwareName)
|
||||
|
||||
default:
|
||||
return obrimLogDirectoryResolveLinux(applicationName)
|
||||
return obrimLogDirectoryResolveLinux(softwareName)
|
||||
}
|
||||
}
|
||||
|
||||
// obrimLogDirectoryResolveLinux resolves Linux log directory paths.
|
||||
func obrimLogDirectoryResolveLinux(applicationName string) string {
|
||||
func obrimLogDirectoryResolveLinux(softwareName string) string {
|
||||
xdgStateHome := strings.TrimSpace(os.Getenv("XDG_STATE_HOME"))
|
||||
|
||||
if xdgStateHome != "" {
|
||||
return filepath.Join(
|
||||
xdgStateHome,
|
||||
"."+applicationName,
|
||||
"."+softwareName,
|
||||
"logs",
|
||||
)
|
||||
}
|
||||
@ -144,7 +144,7 @@ func obrimLogDirectoryResolveLinux(applicationName string) string {
|
||||
if errorValue != nil {
|
||||
return filepath.Join(
|
||||
".",
|
||||
"."+applicationName,
|
||||
"."+softwareName,
|
||||
"logs",
|
||||
)
|
||||
}
|
||||
@ -153,40 +153,40 @@ func obrimLogDirectoryResolveLinux(applicationName string) string {
|
||||
homeDirectory,
|
||||
".local",
|
||||
"state",
|
||||
"."+applicationName,
|
||||
"."+softwareName,
|
||||
"logs",
|
||||
)
|
||||
}
|
||||
|
||||
// obrimLogDirectoryResolveWindows resolves Windows log directory paths.
|
||||
func obrimLogDirectoryResolveWindows(applicationName string) string {
|
||||
localApplicationData := strings.TrimSpace(
|
||||
func obrimLogDirectoryResolveWindows(softwareName string) string {
|
||||
localSoftwareData := strings.TrimSpace(
|
||||
os.Getenv("LOCALAPPDATA"),
|
||||
)
|
||||
|
||||
if localApplicationData == "" {
|
||||
if localSoftwareData == "" {
|
||||
homeDirectory, errorValue := os.UserHomeDir()
|
||||
|
||||
if errorValue == nil {
|
||||
localApplicationData = homeDirectory
|
||||
localSoftwareData = homeDirectory
|
||||
}
|
||||
}
|
||||
|
||||
return filepath.Join(
|
||||
localApplicationData,
|
||||
applicationName,
|
||||
localSoftwareData,
|
||||
softwareName,
|
||||
"Logs",
|
||||
)
|
||||
}
|
||||
|
||||
// obrimLogDirectoryResolveMacOS resolves macOS log directory paths.
|
||||
func obrimLogDirectoryResolveMacOS(applicationName string) string {
|
||||
func obrimLogDirectoryResolveMacOS(softwareName string) string {
|
||||
homeDirectory, errorValue := os.UserHomeDir()
|
||||
|
||||
if errorValue != nil {
|
||||
return filepath.Join(
|
||||
".",
|
||||
"."+applicationName,
|
||||
"."+softwareName,
|
||||
)
|
||||
}
|
||||
|
||||
@ -194,18 +194,18 @@ func obrimLogDirectoryResolveMacOS(applicationName string) string {
|
||||
homeDirectory,
|
||||
"Library",
|
||||
"Logs",
|
||||
"."+applicationName,
|
||||
"."+softwareName,
|
||||
)
|
||||
}
|
||||
|
||||
// obrimLogFileResolve resolves platform-specific log file paths.
|
||||
func obrimLogFileResolve(
|
||||
logDirectory string,
|
||||
applicationName string,
|
||||
softwareName string,
|
||||
) string {
|
||||
return filepath.Join(
|
||||
logDirectory,
|
||||
applicationName+".log",
|
||||
softwareName+".log",
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
| - ObrimRetriever("json", map[string]any{"resource": "metadata"})
|
||||
| - ObrimRetriever("json", map[string]any{
|
||||
| "resource": "metadata",
|
||||
| "path": "application.name",
|
||||
| "path": "software.name",
|
||||
| })
|
||||
|
|
||||
|--------------------------------------------------------------------------
|
||||
@ -43,9 +43,6 @@ package retriever
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"go/module/essential/visible/service/helper/log"
|
||||
"go/module/essential/visible/service/helper/status"
|
||||
)
|
||||
|
||||
// ObrimRetrieverResponse represents the standardized utility response.
|
||||
@ -63,8 +60,6 @@ var ObrimRetrieverDbProviderRegistry = map[string]any{}
|
||||
|
||||
// ObrimRetriever retrieves data using a unified retrieval interface.
|
||||
func ObrimRetriever(retrievalType string, config map[string]any) map[string]any {
|
||||
status.ObrimStatus("INFO", "Retriever started.")
|
||||
log.ObrimLog("INIT", "Retriever execution started.")
|
||||
|
||||
if !obrimRetrieverValidateType(retrievalType) {
|
||||
return obrimRetrieverBuildResponse(false, "FAILED_UNSUPPORTED_TYPE", nil)
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
| Purpose:
|
||||
| - Provide a framework-level CLI status utility that standardizes
|
||||
| terminal message presentation using semantic labels and visual
|
||||
| indicators to ensure consistent output across all applications.
|
||||
| indicators to ensure consistent output across all softwares.
|
||||
|
|
||||
| Guideline:
|
||||
| - Use semantic labels to classify terminal messages.
|
||||
@ -18,7 +18,7 @@
|
||||
| - Intended for framework and software level terminal messaging.
|
||||
|
|
||||
| Example:
|
||||
| - ObrimStatus("INFO", "Application started.")
|
||||
| - ObrimStatus("INFO", "Software started.")
|
||||
| - ObrimStatus("SUCCESS", "Operation completed.")
|
||||
| - ObrimStatus("WARNING", "Configuration missing.")
|
||||
| - ObrimStatus("ERROR", "Operation failed.")
|
||||
|
||||
2
go.mod
2
go.mod
@ -1,3 +1,5 @@
|
||||
module go/module
|
||||
|
||||
go 1.26.4
|
||||
|
||||
require github.com/sqids/sqids-go v0.4.1
|
||||
|
||||
Loading…
Reference in New Issue
Block a user