github.com/sapplications/sb@v0.0.0-20240116135441-1a13cafe3497/public.go (about) 1 // Copyright 2022 Vitalii Noha vitalii.noga@gmail.com. All rights reserved. 2 3 // Package sb implements a Smart Builder application. 4 // It is the next generation of building applications using independent bussiness components. 5 package sb 6 7 import "github.com/hashicorp/go-plugin" 8 9 // SmartCreator creates a new application. 10 type SmartCreator struct { 11 ModManager ModManager 12 Logger Logger 13 } 14 15 // SmartBuilder manages modules and builds the application. 16 type SmartBuilder struct { 17 Builder interface{} 18 ModManager ModManager 19 PluginHandshake plugin.HandshakeConfig 20 Logger Logger 21 } 22 23 // SmartGenerator generates smart builder unit (.sb) using smart application unit. 24 type SmartGenerator struct{} 25 26 // ModManager describes methods for managing a module. 27 type ModManager interface { 28 AddItem(moduleName, itemName string) error 29 AddDependency(itemName, dependencyName, resolver string, update bool) error 30 DeleteItem(itemName string) error 31 DeleteDependency(itemName, dependencyName string) error 32 ReadAll() (ModReader, error) 33 SetLogger(logger Logger) 34 } 35 36 // ModReader describes methods for getting module attributes. 37 type ModReader interface { 38 Items() map[string][][]string 39 Dependency(itemName, dependencyName string) string 40 } 41 42 // ModHelper performs usuful methods. 43 type ModHelper struct { 44 Manager ModManager 45 } 46 47 // Logger describes methods for logging messages. 48 type Logger interface { 49 Trace(msg string, args ...interface{}) 50 Debug(msg string, args ...interface{}) 51 Info(msg string, args ...interface{}) 52 Warn(msg string, args ...interface{}) 53 Error(msg string, args ...interface{}) 54 IsTrace() bool 55 IsDebug() bool 56 IsInfo() bool 57 IsWarn() bool 58 IsError() bool 59 } 60 61 var ModKind = struct { 62 SA string 63 SB string 64 SP string 65 }{ 66 "sa", // smart application unit 67 "sb", // smart builder unit 68 "sp", // smart package unit 69 } 70 71 const ( 72 // application 73 AppName string = "sb" 74 AppVersion string = "1.0" 75 AppVersionString string = AppName + " version " + AppVersion 76 AppsItemName string = "apps" 77 DefaultModuleName string = "apps" 78 // errors 79 ErrorMessageF string = "Error: %v\n" 80 AppIsExistF string = "the specified %s application is exist" 81 AppIsMissing string = "does not found any application in the apps" 82 AppIsMissingF string = "the selected \"%s\" application is not found" 83 AppIsMissingInSystemF string = "the system cannot find the \"%s\" application" 84 AppIsNotSpecified string = "the application is not specified" 85 ItemIsMissingF string = "the %s item is not found" 86 AttrIsMissingF string = "the \"%s\" attribute is missing for \"%s\" application" 87 ModuleFilesMissingF string = "no .%s files in \"" 88 )