github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/internal/svcctl/svcmsg/exitcode.go (about) 1 // Package svcmsg models the Exit Code data that the executor must communicate 2 // to the service. 3 // 4 // IMPORTANT: This package should have minimal dependencies as it will be 5 // imported by cmd/state-exec. The resulting compiled executable must remain as 6 // small as possible. 7 package svcmsg 8 9 import ( 10 "fmt" 11 "strings" 12 ) 13 14 type ExitCode struct { 15 ExecPath string 16 ExitCode string 17 } 18 19 func NewExitCodeFromSvcMsg(data string) *ExitCode { 20 var execPath, exitCode string 21 22 ss := strings.SplitN(data, "<", 2) 23 if len(ss) > 0 { 24 execPath = ss[0] 25 } 26 if len(ss) > 1 { 27 exitCode = ss[1] 28 } 29 30 return NewExitCode(execPath, exitCode) 31 } 32 33 func NewExitCode(execPath, exitCode string) *ExitCode { 34 return &ExitCode{ 35 ExecPath: execPath, 36 ExitCode: exitCode, 37 } 38 } 39 40 func (e *ExitCode) SvcMsg() string { 41 return fmt.Sprintf("exitcode<%s<%s", e.ExecPath, e.ExitCode) 42 }