169 if delstaff != "" {
170 if newstaff != "" {
171 flag.Usage()
172 os.Exit(1)173 }
174 fmt.Printf("Are you sure you want to delete the staff account %q? [y/N]: ", delstaff)
175
164 Str("username", arr[0]).
165 Msg("New staff account created")
166 fmt.Printf("New staff account created: %s\n", arr[0])
167 os.Exit(0)168 }
169 if delstaff != "" {
170 if newstaff != "" {
147 arr := strings.Split(newstaff, ":")
148 if len(arr) < 2 || delstaff != "" {
149 flag.Usage()
150 os.Exit(1)151 }
152 fmt.Printf("Creating new staff: %q, with password: %q and rank: %d from command line", arr[0], arr[1], rank)
153 if _, err = gcsql.NewStaff(arr[0], arr[1], rank); err != nil {
157 }
158 if _, err = os.Stat(cfg.LogDir); err != nil {
159 fmt.Println(err.Error())
160 os.Exit(1)161 }
162
163 cfg.LogDir = gcutil.FindResource(cfg.LogDir, "log", "/var/log/gochan/")
153 }
154 if _, err = os.Stat(cfg.TemplateDir); err != nil {
155 fmt.Println(err.Error())
156 os.Exit(1)157 }
158 if _, err = os.Stat(cfg.LogDir); err != nil {
159 fmt.Println(err.Error())
Packages exposing functions that can stop program execution by exiting are hard to reuse. Program exits in functions other than main() or init() are not encouraged.
func nonMainFunc() {
safelyExit := true // somehow arrive at this value
if safelyExit {
os.Exit(0)
}
}
func main() {
nonMainFunc()
}
func nonMainFunc() bool {
safelyExit := true // somehow arrive at this value
}
func main() {
safelyExit := nonMainFunc()
if safelyExit {
os.Exit(0)
}
}