Files
appcore/open/open.go

29 lines
885 B
Go
Raw Normal View History

2025-06-16 22:26:47 +05:30
// Copyright 2024 Patial Tech (Ankit Patial).
//
// This file is part of code.patial.tech/go/appcore, which is MIT licensed.
// See http://opensource.org/licenses/MIT
2025-06-16 22:19:00 +05:30
package open
// WithDefaultApp open a file, directory, or URI using the OS's default application for that object type.
// The input is validated to prevent path traversal and command injection attacks.
2025-06-16 22:19:00 +05:30
func WithDefaultApp(input string) error {
if err := validateInput(input); err != nil {
return err
}
2025-06-16 22:19:00 +05:30
cmd := open(input)
return cmd.Run()
}
// App will open a file directory, or URI using the specified application.
// Both input and appName are validated to prevent command injection attacks.
2025-06-16 22:19:00 +05:30
func App(input string, appName string) error {
if err := validateInput(input); err != nil {
return err
}
if err := validateAppName(appName); err != nil {
return err
}
2025-06-16 22:19:00 +05:30
return openWith(input, appName).Run()
}