Source File
dataurl.go
Belonging Package
github.com/evanw/esbuild/internal/resolver
package resolver
import (
)
type DataURL struct {
mimeType string
data string
isBase64 bool
}
func ( string) ( DataURL, bool) {
if strings.HasPrefix(, "data:") {
if := strings.IndexByte(, ','); != -1 {
.mimeType = [len("data:"):]
.data = [+1:]
if strings.HasSuffix(.mimeType, ";base64") {
.mimeType = .mimeType[:len(.mimeType)-len(";base64")]
.isBase64 = true
}
= true
}
}
return
}
type MIMEType uint8
const (
MIMETypeUnsupported MIMEType = iota
MIMETypeTextCSS
MIMETypeTextJavaScript
MIMETypeApplicationJSON
)
switch {
case "text/css":
return MIMETypeTextCSS
case "text/javascript":
return MIMETypeTextJavaScript
case "application/json":
return MIMETypeApplicationJSON
default:
return MIMETypeUnsupported
}
}
if .isBase64 {
, := base64.StdEncoding.DecodeString(.data)
if != nil {
return "", fmt.Errorf("Could not decode base64 data: %s", .Error())
}
return string(), nil
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |