Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/cratonica/embed

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/cratonica/embed

  • v0.0.0-20190414040139-05345055fc48
  • Source
  • Go
  • Socket score

Version published
Created
Source

embed

Package embed allows for storing data resources in a virtual filesystem that gets compiled directly into the output program, eliminating the need to distribute data files with the application. This is especially useful for small web servers that need to deliver content files.

The data is gzipped to save space.

An external tool for generating output files can be found here

View the full documentation here

Example

// Create a resource map from files in a directory
resourceMap, _ := embed.CreateFromFiles("/www/js")

// Pack the files into a serializeable byte buffer
packed, _ := embed.Pack(resourceMap)

// Generate a .go file that we can include in our project
goCode := embed.GenerateGoCode("main", "Scripts", packed)
fout, _ := os.Open("scripts.go")
fout.Write([]byte(goCode))
fout.Close()

// ...

// Now in our consumer program, we have a variable called "Scripts"
var Scripts embed.PackedResourceMap

// Unpack the resource map so we can use it
scriptMap, _ := embed.Unpack(Scripts)

// Pull out the resource we want
jquery := scriptMap["jquery/jquery.min.js"]

// Use the embedded file data
fmt.Print(jquery)

FAQs

Package last updated on 14 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc