Friday, April 26, 2024
HomeGolangTips on how to Generate textual content to picture in Golang

Tips on how to Generate textual content to picture in Golang


The explanation why I created this software is for me to share textual content content material like Linux configuration and supply code snippet in WhatsApp or different messaging software. One other is to generate featured picture for social media posts in Twitter, Fb or LinkedIn.

Challenge Construction

Supply code

The entire supply code is offered on github: https://github.com/johnpili/go-text-to-image

The file primary.go comprises the initialization and configuration codes to run this software.

package deal primary

import (
	"flag"
	"github.com/johnpili/go-text-to-image/controllers"
	"github.com/johnpili/go-text-to-image/fashions"
	"io/ioutil"
	"log"
	"web/http"
	"os"
	"strconv"
	"time"

	rice "github.com/GeertJohan/go.rice"
	"github.com/go-zoo/bone"
	"github.com/psi-incontrol/go-sprocket/sprocket"
)

var (
	configuration fashions.Config
)

func primary() {
	pid := os.Getpid()
	err := ioutil.WriteFile("software.pid", []byte(strconv.Itoa(pid)), 0666)
	if err != nil {
		log.Deadly(err)
	}

	var configLocation string
	flag.StringVar(&configLocation, "config", "config.yml", "Set the situation of configuration file")
	flag.Parse()

	sprocket.LoadYAML(configLocation, &configuration)

	viewBox := rice.MustFindBox("views")
	staticBox := rice.MustFindBox("static")
	controllersHub := controllers.New(viewBox, nil, nil, &configuration)
	staticFileServer := http.StripPrefix("/static/", http.FileServer(staticBox.HTTPBox()))

	router := bone.New()
	router.Get("/static/", staticFileServer)
	controllersHub.BindRequestMapping(router)

	// CODE FROM https://medium.com/@mossila/running-go-behind-iis-ce1a610116df
	port := strconv.Itoa(configuration.HTTP.Port)
	if os.Getenv("ASPNETCORE_PORT") != "" { // get enviroment variable that set by ACNM
		port = os.Getenv("ASPNETCORE_PORT")
	}

	httpServer := &http.Server{
		Addr:         ":" + port,
		Handler:      router,
		ReadTimeout:  120 * time.Second,
		WriteTimeout: 120 * time.Second,
	}

	if configuration.HTTP.IsTLS {
		log.Printf("Server operating at https://localhost/instruments:%s/n", port)
		log.Deadly(httpServer.ListenAndServeTLS(configuration.HTTP.ServerCert, configuration.HTTP.ServerKey))
		return
	}
	log.Printf("Server operating at http://localhost/instruments:%s/n", port)
	log.Deadly(httpServer.ListenAndServe())
}
The page_controller.go handles each the web page rendering and picture technology.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments