github.com/geniusesgroup/libgo@v0.0.0-20220713101832-828057a9d3d4/www/assets.go (about)

     1  /* For license and copyright information please see LEGAL file in repository */
     2  
     3  package www
     4  
     5  import (
     6  	"fmt"
     7  
     8  	"../protocol"
     9  )
    10  
    11  const (
    12  	guiDirectoryName      = "gui"
    13  	mainHTMLDirectoryName = "main-html"
    14  )
    15  
    16  type Assets struct {
    17  	GUI         protocol.FileDirectory
    18  	MainHTMLDir protocol.FileDirectory // files name is just language in iso format e.g. "en", "fa",
    19  	// OldBrowsers protocol.FileDirectory // files name is just language in iso format e.g. "en", "fa",
    20  	ContentEncodings []string
    21  }
    22  
    23  func (a *Assets) Init() {
    24  	var err protocol.Error
    25  	a.GUI, err = protocol.App.Files().Directory(guiDirectoryName)
    26  	protocol.App.LogFatal(err)
    27  	a.MainHTMLDir, err = a.GUI.Directory(mainHTMLDirectoryName)
    28  	protocol.App.LogFatal(err)
    29  	a.update()
    30  }
    31  
    32  // ReloadByCLI block function and must call by seprate goroutine, otherwise it can block other app logic!
    33  func (a *Assets) ReloadByCLI() {
    34  	// defer Server.PanicHandler()
    35  reload:
    36  	protocol.App.Log(protocol.LogType_Information, "Write '''R''' & press '''Enter''' key to reload GUI changes")
    37  	var non string
    38  	fmt.Scanln(&non)
    39  	if non == "R" || non == "r" {
    40  		a.update()
    41  	} else {
    42  		protocol.App.Log(protocol.LogType_Warning, "Requested command not found")
    43  	}
    44  	goto reload
    45  }
    46  
    47  // Update use to add needed repo files that get from disk or network to the assets!!
    48  func (a *Assets) update() {
    49  	var c = combine{
    50  		contentEncodings: a.ContentEncodings,
    51  	}
    52  	c.update()
    53  	protocol.App.Log(protocol.LogType_Information, "WWW - GUI assets successfully updated and ready to serve")
    54  }