-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Steve Fan <29133953+stevefan1999-personal@users.noreply.github.com>
- Loading branch information
1 parent
50ba9cb
commit e2b2e08
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package main | ||
|
||
type ProviderShortName interface { | ||
ShortName() string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
) | ||
|
||
type ProviderUtil interface { | ||
WriteDataToFile(contentTrait string, permission os.FileMode, content string, dest string) error | ||
MakeFolder(folderTrait string, permission os.FileMode, dest string) error | ||
} | ||
|
||
type DefaultProviderUtil struct { | ||
ProviderUtil | ||
ProviderShortName | ||
} | ||
|
||
func (p *DefaultProviderUtil) WriteDataToFile(contentTrait string, permission os.FileMode, content string, dest string) error { | ||
if err := ioutil.WriteFile(dest, []byte(content), permission); err != nil { | ||
return fmt.Errorf("%s: failed to write %s: %s", p.ShortName(), contentTrait, err) | ||
} | ||
return nil | ||
} | ||
|
||
func (p *DefaultProviderUtil) MakeFolder(folderTrait string, permission os.FileMode, dest string) error { | ||
if err := os.Mkdir(dest, permission); err != nil { | ||
return fmt.Errorf("%s: failed to make folder for %s: %s", p.ShortName(), folderTrait, err) | ||
} | ||
return nil | ||
} |