Skip to content
András Belicza edited this page Sep 26, 2017 · 3 revisions

Frequently asked questions and answers regarding to Gowut.

Table of Contents

1. How can I add/include my custom, external CSS file?
2. How can I periodically refresh a component?
3. How can I specify HTTP response headers that are sent with all responses?

1. How can I add/include my custom, external CSS file?

There are 2 main ways to include custom CSS content.

  1. If you have a short CSS code you want to include, you can include it with the Window.AddHeadHTML() method. For example to make all labels red by default:

     win.AddHeadHTML("<style>.gwu-Label{color:red}</style>")
    
  2. If you have a long CSS code or you have it as an external file, then the recommended way is this to tell Gowut about the location of this (and other static files). You can do that with the Server.AddStaticDir() method. After that you can link to this file using Window.AddHeadHTML():

     serv.AddStaticDir("static", "/temp/staticfiles")
     win.AddHeadHTML(`<link rel="stylesheet" type="text/css" href="/appname/static/mystyle.css">`)
    

2. How can I periodically refresh a component?

You can use the Timer component to generate a series of events periodically, and add an event handler to it in which you can change the component and mark it dirty.

t := gwu.NewTimer(10 * time.Second)
t.AddEHandlerFunc(func(e gwu.Event) {
    timelabel.SetText(time.Now().Format("15:04:05"))
    e.MarkDirty(timelabel)
}, gwu.ETypeStateChange)

3. How can I specify HTTP response headers that are sent with all responses?

Gowut 1.0.0 added 2 new methods in Server: SetHeader() and Header(). Using SetHeader():

server.SetHeaders(map[string][]string{
    "Gowut-Server": {gwu.GowutVersion},
})