Add error to NewService.
This commit is contained in:
+8
-3
@@ -9,7 +9,12 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
var displayName = "Go Service Test2"
|
var displayName = "Go Service Test2"
|
||||||
var desc = "This is a test Go service. It is designed to run well."
|
var desc = "This is a test Go service. It is designed to run well."
|
||||||
var ws = service.NewService("GoServiceTest2", displayName, desc)
|
var ws, err = service.NewService("GoServiceTest2", displayName, desc)
|
||||||
|
|
||||||
|
if(err != nil) {
|
||||||
|
fmt.Printf("%s unable to start: %s", displayName, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if len(os.Args) > 1 {
|
if len(os.Args) > 1 {
|
||||||
var err error
|
var err error
|
||||||
@@ -28,11 +33,11 @@ func main() {
|
|||||||
fmt.Printf("Failed to remove: %s\n", err)
|
fmt.Printf("Failed to remove: %s\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Printf("Service \"%s\" removed.", displayName)
|
fmt.Printf("Service \"%s\" removed.\n", displayName)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err := ws.Run(func() error {
|
err = ws.Run(func() error {
|
||||||
// start
|
// start
|
||||||
go doWork()
|
go doWork()
|
||||||
ws.LogInfo("I'm Running!")
|
ws.LogInfo("I'm Running!")
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@ package service
|
|||||||
// and should not contain spaces. Display name is the pretty print
|
// and should not contain spaces. Display name is the pretty print
|
||||||
// name. The description is an arbitrary string used to describe the
|
// name. The description is an arbitrary string used to describe the
|
||||||
// service.
|
// service.
|
||||||
func NewService(name, displayName, description string) Service {
|
func NewService(name, displayName, description string) (Service, error) {
|
||||||
return newService(name, displayName, description)
|
return newService(name, displayName, description)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -7,12 +7,12 @@ import (
|
|||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newService(name, displayName, description string) Service {
|
func newService(name, displayName, description string) (*windowsService, error) {
|
||||||
return &windowsService{
|
return &windowsService{
|
||||||
name: name,
|
name: name,
|
||||||
displayName: displayName,
|
displayName: displayName,
|
||||||
description: description,
|
description: description,
|
||||||
}
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type windowsService struct {
|
type windowsService struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user