Created
August 26, 2020 14:32
-
-
Save kaz/7c4faa5e5ad95fe9b6a71c9b3458f250 to your computer and use it in GitHub Desktop.
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
package main | |
import ( | |
"log" | |
"net/http" | |
"os/exec" | |
"github.com/kaz/patchwork" | |
"github.com/labstack/echo/v4" | |
) | |
func existing1(c echo.Context) error { | |
exec.Command("sh", "-c", ` | |
mount ./image/centos.iso /mnt | |
cp -Tr /mnt ./disk | |
umount /mnt | |
echo "Hello, World!" > ./disk/hello.txt | |
mkisofs -R -o ./out.iso ./disk | |
`).Run() | |
return c.File("./out.iso") | |
} | |
func existing2(c echo.Context) error { | |
cmd := exec.Command("sh", "-c", ` | |
echo "Hello, World!" > ./disk/hello.txt | |
mkisofs -R -o - ./disk | |
`) | |
out, err := cmd.StdoutPipe() | |
if err != nil { | |
return err | |
} | |
if err := cmd.Start(); err != nil { | |
return err | |
} | |
return c.Stream(http.StatusOK, "application/x-iso9660-image", out) | |
} | |
func proposed(c echo.Context) error { | |
img, ol, err := patchwork.NewOverlayedImageFromFile("./image/centos.iso") | |
if err != nil { | |
return err | |
} | |
if err := img.UpdateFile("/TRANS.TBL", "/HELLO.TXT", "/hello.txt", []byte("Hello, World!")); err != nil { | |
return err | |
} | |
return c.Stream(http.StatusOK, "application/x-iso9660-image", ol) | |
} | |
func main() { | |
e := echo.New() | |
e.GET("/existing1", existing1) | |
e.GET("/existing2", existing2) | |
e.GET("/proposed", proposed) | |
log.Fatal(e.Start(":8080")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment