github.com/oweisse/u-root@v0.0.0-20181109060735-d005ad25fef1/examples/sos/service.go (about) 1 // Copyright 2018 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 // Your service.go file will be heavily tailored for the problem you are trying to solve. 8 // a type representing your service and a constructor for that service are all that is 9 // specifically required. If you are depending on something outside of the program, such 10 // as text files or system settings, add an update function which loads that data into your 11 // service struct. 12 13 // the one field in our example service is a string, set by the user. 14 type ExampleService struct { 15 Example string 16 } 17 18 // here is where you'd define an update function. Since this demo does not depend on any 19 // system settings, I have omitted it. 20 21 // define any service functionality here. 22 // ExampleServiceFunc1: Set service variable to input 23 func (es *ExampleService) ExampleServiceFunc1(input ExampleJsonMsg) error { 24 es.Example = input.Example 25 return nil 26 } 27 28 // ExampleServiceFunc2: Reset service variable to empty string 29 func (es *ExampleService) ExampleServiceFunc2() error { 30 es.Example = "" 31 return nil 32 } 33 34 // NewExampleService: construct a new service 35 // If your service controls system settings, make a getCurrentSetting() function to 36 // initialize your service. 37 func NewExampleService() (*ExampleService, error) { 38 return &ExampleService{ 39 Example: "", 40 }, nil 41 }