mirror of
https://github.com/taigrr/wails.git
synced 2026-04-17 12:15:02 -07:00
Compare commits
14 Commits
v2.0.0-alp
...
v2.0.0-alp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
265328d648 | ||
|
|
6f40e85a6e | ||
|
|
96d8509da3 | ||
|
|
598445ab0f | ||
|
|
24788e2fd3 | ||
|
|
bbf4dde43f | ||
|
|
0afd27ab45 | ||
|
|
d498423ec2 | ||
|
|
66ce84973c | ||
|
|
55e6a0f312 | ||
|
|
81e83fdf18 | ||
|
|
f9b79d24f8 | ||
|
|
0599a47bfe | ||
|
|
817c55d318 |
@@ -1,3 +1,3 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
var version = "v2.0.0-alpha.45"
|
var version = "v2.0.0-alpha.51"
|
||||||
|
|||||||
@@ -128,6 +128,7 @@ struct Application {
|
|||||||
int hideToolbarSeparator;
|
int hideToolbarSeparator;
|
||||||
int windowBackgroundIsTranslucent;
|
int windowBackgroundIsTranslucent;
|
||||||
int hasURLHandlers;
|
int hasURLHandlers;
|
||||||
|
const char *startupURL;
|
||||||
|
|
||||||
// Menu
|
// Menu
|
||||||
Menu *applicationMenu;
|
Menu *applicationMenu;
|
||||||
@@ -144,6 +145,9 @@ struct Application {
|
|||||||
// shutting down flag
|
// shutting down flag
|
||||||
bool shuttingDown;
|
bool shuttingDown;
|
||||||
|
|
||||||
|
// Running flag
|
||||||
|
bool running;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Debug works like sprintf but mutes if the global debug flag is true
|
// Debug works like sprintf but mutes if the global debug flag is true
|
||||||
@@ -304,8 +308,19 @@ void messageHandler(id self, SEL cmd, id contentController, id message) {
|
|||||||
// TODO: Check this actually does reduce flicker
|
// TODO: Check this actually does reduce flicker
|
||||||
msg(app->config, s("setValue:forKey:"), msg(c("NSNumber"), s("numberWithBool:"), 0), str("suppressesIncrementalRendering"));
|
msg(app->config, s("setValue:forKey:"), msg(c("NSNumber"), s("numberWithBool:"), 0), str("suppressesIncrementalRendering"));
|
||||||
|
|
||||||
|
// We are now running!
|
||||||
|
app->running = true;
|
||||||
|
|
||||||
|
|
||||||
// Notify backend we are ready (system startup)
|
// Notify backend we are ready (system startup)
|
||||||
app->sendMessageToBackend("SS");
|
const char *readyMessage = "SS";
|
||||||
|
if( app->startupURL == NULL ) {
|
||||||
|
app->sendMessageToBackend("SS");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
readyMessage = concat("SS", app->startupURL);
|
||||||
|
app->sendMessageToBackend(readyMessage);
|
||||||
|
MEMFREE(readyMessage);
|
||||||
|
|
||||||
} else if( strcmp(name, "windowDrag") == 0 ) {
|
} else if( strcmp(name, "windowDrag") == 0 ) {
|
||||||
// Guard against null events
|
// Guard against null events
|
||||||
@@ -403,6 +418,11 @@ void ExecJS(struct Application *app, const char *js) {
|
|||||||
|
|
||||||
void willFinishLaunching(id self, SEL cmd, id sender) {
|
void willFinishLaunching(id self, SEL cmd, id sender) {
|
||||||
struct Application *app = (struct Application *) objc_getAssociatedObject(self, "application");
|
struct Application *app = (struct Application *) objc_getAssociatedObject(self, "application");
|
||||||
|
// If there are URL Handlers, register a listener for them
|
||||||
|
if( app->hasURLHandlers ) {
|
||||||
|
id eventManager = msg(c("NSAppleEventManager"), s("sharedAppleEventManager"));
|
||||||
|
msg(eventManager, s("setEventHandler:andSelector:forEventClass:andEventID:"), self, s("getUrl:withReplyEvent:"), kInternetEventClass, kAEGetURL);
|
||||||
|
}
|
||||||
messageFromWindowCallback("Ej{\"name\":\"wails:launched\",\"data\":[]}");
|
messageFromWindowCallback("Ej{\"name\":\"wails:launched\",\"data\":[]}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -427,12 +447,6 @@ void themeChanged(id self, SEL cmd, id sender) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// void willFinishLaunching(id self) {
|
|
||||||
// struct Application *app = (struct Application *) objc_getAssociatedObject(self, "application");
|
|
||||||
// Debug(app, "willFinishLaunching called!");
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
int releaseNSObject(void *const context, struct hashmap_element_s *const e) {
|
int releaseNSObject(void *const context, struct hashmap_element_s *const e) {
|
||||||
msg(e->data, s("release"));
|
msg(e->data, s("release"));
|
||||||
return -1;
|
return -1;
|
||||||
@@ -465,6 +479,10 @@ void DestroyApplication(struct Application *app) {
|
|||||||
Debug(app, "Almost a double free for app->bindings");
|
Debug(app, "Almost a double free for app->bindings");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( app->startupURL != NULL ) {
|
||||||
|
MEMFREE(app->startupURL);
|
||||||
|
}
|
||||||
|
|
||||||
// Remove mouse monitors
|
// Remove mouse monitors
|
||||||
if( app->mouseDownMonitor != NULL ) {
|
if( app->mouseDownMonitor != NULL ) {
|
||||||
msg( c("NSEvent"), s("removeMonitor:"), app->mouseDownMonitor);
|
msg( c("NSEvent"), s("removeMonitor:"), app->mouseDownMonitor);
|
||||||
@@ -1156,46 +1174,58 @@ void DarkModeEnabled(struct Application *app, const char *callbackID) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void getURL(id self, SEL selector, id event, id replyEvent) {
|
void getURL(id self, SEL selector, id event, id replyEvent) {
|
||||||
id desc = msg(event, s("paramDescriptorForKeyword:"), keyDirectObject);
|
struct Application *app = (struct Application *)objc_getAssociatedObject(self, "application");
|
||||||
id url = msg(desc, s("stringValue"));
|
id desc = msg(event, s("paramDescriptorForKeyword:"), keyDirectObject);
|
||||||
const char* curl = cstr(url);
|
id url = msg(desc, s("stringValue"));
|
||||||
const char* message = concat("UC", curl);
|
const char* curl = cstr(url);
|
||||||
messageFromWindowCallback(message);
|
if( curl == NULL ) {
|
||||||
MEMFREE(message);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If this was an incoming URL, but we aren't running yet
|
||||||
|
// save it to return when we complete
|
||||||
|
if( app->running != true ) {
|
||||||
|
app->startupURL = STRCOPY(curl);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* message = concat("UC", curl);
|
||||||
|
messageFromWindowCallback(message);
|
||||||
|
MEMFREE(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
void openURLs(id self, SEL selector, id event) {
|
||||||
|
filelog("\n\nI AM HERE!!!!!\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void createDelegate(struct Application *app) {
|
void createDelegate(struct Application *app) {
|
||||||
|
|
||||||
// Define delegate
|
// Define delegate
|
||||||
Class delegateClass = objc_allocateClassPair((Class) c("NSObject"), "AppDelegate", 0);
|
Class appDelegate = objc_allocateClassPair((Class) c("NSResponder"), "AppDelegate", 0);
|
||||||
bool resultAddProtoc = class_addProtocol(delegateClass, objc_getProtocol("NSApplicationDelegate"));
|
class_addProtocol(appDelegate, objc_getProtocol("NSTouchBarProvider"));
|
||||||
class_addMethod(delegateClass, s("applicationShouldTerminateAfterLastWindowClosed:"), (IMP) no, "c@:@");
|
|
||||||
class_addMethod(delegateClass, s("applicationWillFinishLaunching:"), (IMP) willFinishLaunching, "v@:@");
|
class_addMethod(appDelegate, s("applicationShouldTerminateAfterLastWindowClosed:"), (IMP) no, "c@:@");
|
||||||
|
class_addMethod(appDelegate, s("applicationWillFinishLaunching:"), (IMP) willFinishLaunching, "v@:@");
|
||||||
|
|
||||||
// All Menu Items use a common callback
|
// All Menu Items use a common callback
|
||||||
class_addMethod(delegateClass, s("menuItemCallback:"), (IMP)menuItemCallback, "v@:@");
|
class_addMethod(appDelegate, s("menuItemCallback:"), (IMP)menuItemCallback, "v@:@");
|
||||||
|
|
||||||
// If there are URL Handlers, register the callback method
|
// If there are URL Handlers, register the callback method
|
||||||
if( app->hasURLHandlers ) {
|
if( app->hasURLHandlers ) {
|
||||||
class_addMethod(delegateClass, s("getUrl:withReplyEvent:"), (IMP) getURL, "i@:@@");
|
class_addMethod(appDelegate, s("getUrl:withReplyEvent:"), (IMP) getURL, "i@:@@");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Script handler
|
// Script handler
|
||||||
class_addMethod(delegateClass, s("userContentController:didReceiveScriptMessage:"), (IMP) messageHandler, "v@:@@");
|
class_addMethod(appDelegate, s("userContentController:didReceiveScriptMessage:"), (IMP) messageHandler, "v@:@@");
|
||||||
objc_registerClassPair(delegateClass);
|
objc_registerClassPair(appDelegate);
|
||||||
|
|
||||||
// Create delegate
|
// Create delegate
|
||||||
id delegate = msg((id)delegateClass, s("new"));
|
id delegate = msg((id)appDelegate, s("new"));
|
||||||
objc_setAssociatedObject(delegate, "application", (id)app, OBJC_ASSOCIATION_ASSIGN);
|
objc_setAssociatedObject(delegate, "application", (id)app, OBJC_ASSOCIATION_ASSIGN);
|
||||||
|
|
||||||
// If there are URL Handlers, register a listener for them
|
|
||||||
if( app->hasURLHandlers ) {
|
|
||||||
id eventManager = msg(c("NSAppleEventManager"), s("sharedAppleEventManager"));
|
|
||||||
msg(eventManager, s("setEventHandler:andSelector:forEventClass:andEventID:"), delegate, s("getUrl:withReplyEvent:"), kInternetEventClass, kAEGetURL);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Theme change listener
|
// Theme change listener
|
||||||
class_addMethod(delegateClass, s("themeChanged:"), (IMP) themeChanged, "v@:@@");
|
class_addMethod(appDelegate, s("themeChanged:"), (IMP) themeChanged, "v@:@@");
|
||||||
|
|
||||||
// Get defaultCenter
|
// Get defaultCenter
|
||||||
id defaultCenter = msg(c("NSDistributedNotificationCenter"), s("defaultCenter"));
|
id defaultCenter = msg(c("NSDistributedNotificationCenter"), s("defaultCenter"));
|
||||||
@@ -1974,6 +2004,10 @@ void* NewApplication(const char *title, int width, int height, int resizable, in
|
|||||||
|
|
||||||
result->hasURLHandlers = 0;
|
result->hasURLHandlers = 0;
|
||||||
|
|
||||||
|
result->startupURL = NULL;
|
||||||
|
|
||||||
|
result->running = false;
|
||||||
|
|
||||||
return (void*) result;
|
return (void*) result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -604,7 +604,7 @@ id processTextMenuItem(Menu *menu, id parentMenu, const char *title, const char
|
|||||||
id nsimage = ALLOC("NSImage");
|
id nsimage = ALLOC("NSImage");
|
||||||
msg(nsimage, s("initWithData:"), imageData);
|
msg(nsimage, s("initWithData:"), imageData);
|
||||||
if( templateImage ) {
|
if( templateImage ) {
|
||||||
msg(nsimage, s("template"), YES);
|
msg(nsimage, s("setTemplate:"), YES);
|
||||||
}
|
}
|
||||||
msg(item, s("setImage:"), nsimage);
|
msg(item, s("setImage:"), nsimage);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,8 +82,18 @@ void UpdateTrayIcon(TrayMenu *trayMenu) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
id trayImage = hashmap_get(&trayIconCache, trayMenu->icon, strlen(trayMenu->icon));
|
id trayImage = hashmap_get(&trayIconCache, trayMenu->icon, strlen(trayMenu->icon));
|
||||||
|
|
||||||
|
// If we don't have the image in the icon cache then assume it's base64 encoded image data
|
||||||
|
if (trayImage == NULL) {
|
||||||
|
id data = ALLOC("NSData");
|
||||||
|
id imageData = msg(data, s("initWithBase64EncodedString:options:"), str(trayMenu->icon), 0);
|
||||||
|
trayImage = ALLOC("NSImage");
|
||||||
|
msg(trayImage, s("initWithData:"), imageData);
|
||||||
|
}
|
||||||
|
|
||||||
msg(statusBarButton, s("setImagePosition:"), trayMenu->trayIconPosition);
|
msg(statusBarButton, s("setImagePosition:"), trayMenu->trayIconPosition);
|
||||||
msg(statusBarButton, s("setImage:"), trayImage);
|
msg(statusBarButton, s("setImage:"), trayImage);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowTrayMenu(TrayMenu* trayMenu) {
|
void ShowTrayMenu(TrayMenu* trayMenu) {
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ func systemMessageParser(message string) (*parsedMessage, error) {
|
|||||||
// This is our startup hook - the frontend is now ready
|
// This is our startup hook - the frontend is now ready
|
||||||
case 'S':
|
case 'S':
|
||||||
topic := "hooks:startup"
|
topic := "hooks:startup"
|
||||||
responseMessage = &parsedMessage{Topic: topic, Data: nil}
|
startupURL := message[1:]
|
||||||
|
responseMessage = &parsedMessage{Topic: topic, Data: startupURL}
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("Invalid message to systemMessageParser()")
|
return nil, fmt.Errorf("Invalid message to systemMessageParser()")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,9 @@ type Runtime struct {
|
|||||||
|
|
||||||
// Startup Hook
|
// Startup Hook
|
||||||
startupOnce sync.Once
|
startupOnce sync.Once
|
||||||
|
|
||||||
|
// Service bus
|
||||||
|
bus *servicebus.ServiceBus
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRuntime creates a new runtime subsystem
|
// NewRuntime creates a new runtime subsystem
|
||||||
@@ -58,6 +61,7 @@ func NewRuntime(ctx context.Context, bus *servicebus.ServiceBus, logger *logger.
|
|||||||
runtime: runtime.New(bus),
|
runtime: runtime.New(bus),
|
||||||
startupCallback: startupCallback,
|
startupCallback: startupCallback,
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
|
bus: bus,
|
||||||
}
|
}
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
@@ -79,7 +83,15 @@ func (r *Runtime) Start() error {
|
|||||||
case "startup":
|
case "startup":
|
||||||
if r.startupCallback != nil {
|
if r.startupCallback != nil {
|
||||||
r.startupOnce.Do(func() {
|
r.startupOnce.Do(func() {
|
||||||
go r.startupCallback(r.runtime)
|
go func() {
|
||||||
|
r.startupCallback(r.runtime)
|
||||||
|
|
||||||
|
// If we got a url, publish it now startup completed
|
||||||
|
url, ok := hooksMessage.Data().(string)
|
||||||
|
if ok && len(url) > 0 {
|
||||||
|
r.bus.Publish("url:handler", url)
|
||||||
|
}
|
||||||
|
}()
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
r.logger.Warning("no startup callback registered!")
|
r.logger.Warning("no startup callback registered!")
|
||||||
|
|||||||
@@ -68,6 +68,10 @@ func (u *URL) Start() error {
|
|||||||
u.wg.Done()
|
u.wg.Done()
|
||||||
return
|
return
|
||||||
case urlMessage := <-u.urlChannel:
|
case urlMessage := <-u.urlChannel:
|
||||||
|
// Guard against nil messages
|
||||||
|
if urlMessage == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
messageType := strings.TrimPrefix(urlMessage.Topic(), "url:")
|
messageType := strings.TrimPrefix(urlMessage.Topic(), "url:")
|
||||||
switch messageType {
|
switch messageType {
|
||||||
case "handler":
|
case "handler":
|
||||||
|
|||||||
@@ -223,9 +223,6 @@ func (b *BaseBuilder) CompileProject(options *Options) error {
|
|||||||
// Set the directory
|
// Set the directory
|
||||||
cmd.Dir = b.projectData.Path
|
cmd.Dir = b.projectData.Path
|
||||||
|
|
||||||
// Set GO111MODULE environment variable
|
|
||||||
cmd.Env = append(os.Environ(), "GO111MODULE=on")
|
|
||||||
|
|
||||||
// Add CGO flags
|
// Add CGO flags
|
||||||
// We use the project/build dir as a temporary place for our generated c headers
|
// We use the project/build dir as a temporary place for our generated c headers
|
||||||
buildBaseDir, err := fs.RelativeToCwd("build")
|
buildBaseDir, err := fs.RelativeToCwd("build")
|
||||||
@@ -233,7 +230,16 @@ func (b *BaseBuilder) CompileProject(options *Options) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Env = append(os.Environ(), fmt.Sprintf("CGO_CFLAGS=-I%s", buildBaseDir))
|
cmd.Env = os.Environ() // inherit env
|
||||||
|
|
||||||
|
// Use upsertEnv so we don't overwrite user's CGO_CFLAGS
|
||||||
|
cmd.Env = upsertEnv(cmd.Env, "CGO_CFLAGS", func(v string) string {
|
||||||
|
if v != "" {
|
||||||
|
v += " "
|
||||||
|
}
|
||||||
|
v += "-I" + buildBaseDir
|
||||||
|
return v
|
||||||
|
})
|
||||||
|
|
||||||
// Setup buffers
|
// Setup buffers
|
||||||
var stdo, stde bytes.Buffer
|
var stdo, stde bytes.Buffer
|
||||||
@@ -391,3 +397,22 @@ func (b *BaseBuilder) ExtractAssets() (*html.AssetBundle, error) {
|
|||||||
// Read in html
|
// Read in html
|
||||||
return html.NewAssetBundle(b.projectData.HTML)
|
return html.NewAssetBundle(b.projectData.HTML)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func upsertEnv(env []string, key string, update func(v string) string) []string {
|
||||||
|
newEnv := make([]string, len(env), len(env)+1)
|
||||||
|
found := false
|
||||||
|
for i := range env {
|
||||||
|
if strings.HasPrefix(env[i], key+"=") {
|
||||||
|
eqIndex := strings.Index(env[i], "=")
|
||||||
|
val := env[i][eqIndex+1:]
|
||||||
|
newEnv[i] = fmt.Sprintf("%s=%v", key, update(val))
|
||||||
|
found = true
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
newEnv[i] = env[i]
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
newEnv = append(newEnv, fmt.Sprintf("%s=%v", key, update("")))
|
||||||
|
}
|
||||||
|
return newEnv
|
||||||
|
}
|
||||||
|
|||||||
31
v2/pkg/commands/build/base_test.go
Normal file
31
v2/pkg/commands/build/base_test.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package build
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestUpdateEnv(t *testing.T) {
|
||||||
|
|
||||||
|
env := []string{"one=1", "two=a=b", "three="}
|
||||||
|
newEnv := upsertEnv(env, "two", func(v string) string {
|
||||||
|
return v + "+added"
|
||||||
|
})
|
||||||
|
newEnv = upsertEnv(newEnv, "newVar", func(v string) string {
|
||||||
|
return "added"
|
||||||
|
})
|
||||||
|
newEnv = upsertEnv(newEnv, "three", func(v string) string {
|
||||||
|
return "3"
|
||||||
|
})
|
||||||
|
|
||||||
|
if len(newEnv) != 4 {
|
||||||
|
t.Errorf("expected: 4, got: %d", len(newEnv))
|
||||||
|
}
|
||||||
|
if newEnv[1] != "two=a=b+added" {
|
||||||
|
t.Errorf("expected: \"two=a=b+added\", got: %q", newEnv[1])
|
||||||
|
}
|
||||||
|
if newEnv[2] != "three=3" {
|
||||||
|
t.Errorf("expected: \"three=3\", got: %q", newEnv[2])
|
||||||
|
}
|
||||||
|
if newEnv[3] != "newVar=added" {
|
||||||
|
t.Errorf("expected: \"newVar=added\", got: %q", newEnv[3])
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
66
v2/pkg/logger/filelogger.go
Normal file
66
v2/pkg/logger/filelogger.go
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
package logger
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
// FileLogger is a utility to log messages to a number of destinations
|
||||||
|
type FileLogger struct {
|
||||||
|
filename string
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewFileLogger creates a new Logger.
|
||||||
|
func NewFileLogger(filename string) Logger {
|
||||||
|
return &FileLogger{
|
||||||
|
filename: filename,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print works like Sprintf.
|
||||||
|
func (l *FileLogger) Print(message string) {
|
||||||
|
f, err := os.OpenFile(l.filename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := f.WriteString(message); err != nil {
|
||||||
|
f.Close()
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
f.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *FileLogger) Println(message string) {
|
||||||
|
l.Print(message + "\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trace level logging. Works like Sprintf.
|
||||||
|
func (l *FileLogger) Trace(message string) {
|
||||||
|
l.Println("TRACE | " + message)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debug level logging. Works like Sprintf.
|
||||||
|
func (l *FileLogger) Debug(message string) {
|
||||||
|
l.Println("DEBUG | " + message)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Info level logging. Works like Sprintf.
|
||||||
|
func (l *FileLogger) Info(message string) {
|
||||||
|
l.Println("INFO | " + message)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Warning level logging. Works like Sprintf.
|
||||||
|
func (l *FileLogger) Warning(message string) {
|
||||||
|
l.Println("WARN | " + message)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error level logging. Works like Sprintf.
|
||||||
|
func (l *FileLogger) Error(message string) {
|
||||||
|
l.Println("ERROR | " + message)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fatal level logging. Works like Sprintf.
|
||||||
|
func (l *FileLogger) Fatal(message string) {
|
||||||
|
l.Println("FATAL | " + message)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
@@ -30,7 +30,8 @@ var modifierMap = map[string]Modifier{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func parseModifier(text string) (*Modifier, error) {
|
func parseModifier(text string) (*Modifier, error) {
|
||||||
result, valid := modifierMap[text]
|
lowertext := strings.ToLower(text)
|
||||||
|
result, valid := modifierMap[lowertext]
|
||||||
if !valid {
|
if !valid {
|
||||||
return nil, fmt.Errorf("'%s' is not a valid modifier", text)
|
return nil, fmt.Errorf("'%s' is not a valid modifier", text)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user