forked from saturn4er/beego-assets
-
Notifications
You must be signed in to change notification settings - Fork 1
/
API.go
45 lines (38 loc) · 1.54 KB
/
API.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package beegoAssets
import (
"crypto/md5"
"fmt"
)
// SetAssetFileExtension - add new Asset type
func SetAssetFileExtension(extension string, assetType assetsType) {
Config.extensions[assetType] = append(Config.extensions[assetType], extension)
}
// SetPreLoadCallback - set callback on preload assets
func SetPreLoadCallback(assetType assetsType, cb preLoadCallback) {
if _, ok := Config.preLoadCallbacks[assetType]; !ok {
Config.preLoadCallbacks[assetType] = []preLoadCallback{}
}
Config.preLoadCallbacks[assetType] = append(Config.preLoadCallbacks[assetType], cb)
}
// SetPreBuildCallback - set callback on PreBuild assets
func SetPreBuildCallback(assetType assetsType, cb preAfterBuildCallback) {
if _, ok := Config.preBuildCallbacks[assetType]; !ok {
Config.preBuildCallbacks[assetType] = []preAfterBuildCallback{}
}
Config.preBuildCallbacks[assetType] = append(Config.preBuildCallbacks[assetType], cb)
}
// SetAfterBuildCallback - set callback on after build assets
func SetAfterBuildCallback(assetType assetsType, cb preAfterBuildCallback) {
if _, ok := Config.afterBuildCallbacks[assetType]; !ok {
Config.afterBuildCallbacks[assetType] = []preAfterBuildCallback{}
}
Config.afterBuildCallbacks[assetType] = append(Config.afterBuildCallbacks[assetType], cb)
}
// SetMinifyCallback -
func SetMinifyCallback(extension string, cb minifyFileCallback) {
Config.minifyCallbacks[extension] = cb
}
// GetAssetFileHash - get hash(fingerprint) file by body
func GetAssetFileHash(body *string) string {
return fmt.Sprintf("%x", md5.Sum([]byte(*body)))
}