Arquivo da categoria: Framework

Certificado com o IRIS

package main

import (
	"github.com/kataras/iris"
	"github.com/kataras/iris/context"
)

func main() {
	app := iris.New()

	app.Get("/", func(ctx context.Context) {
		ctx.Writef("Hello from the SECURE server")
	})

	// start the server (HTTPS) on port 443
	app.Run(iris.TLS("127.0.0.1:443", "mycert.cert", "mykey.key"))
}
https://chekun.me/post/iris-from-scratch-02-listen-and-configuration/

Share and Enjoy !

0Shares
0 0

golang Iris – function to view

 // Default template funcs are:
    //
    // - {{ urlpath "myNamedRoute" "pathParameter_ifNeeded" }}
    // - {{ render "header.html" }}
    // and partial relative path to current page:
    // - {{ render_r "header.html" }} 
    // - {{ yield }}
    // - {{ current }}
    // Register a custom template func:
    tmpl.AddFunc("greet", func(s string) string {
        return "Greetings " + s + "!"
    })
https://github.com/kataras/iris/wiki/View

Share and Enjoy !

0Shares
0 0

golang iris return directly template html

package controllers

import (
    "github.com/kataras/iris/mvc"
)
type HelloController struct{}

var helloView = mvc.View{
    Name: "hello/index.html",
    Data: map[string]interface{}{
        "Title":     "Hello Page",
        //"MyMessage": "Welcome to my awesome website",
    },
}
func (c *HelloController) Get() mvc.Result {
    return helloView
}
https://stackoverflow.com/questions/51099508/golang-iris-return-directly-template-html

Share and Enjoy !

0Shares
0 0

Golang Iris – golog

Share and Enjoy !

0Shares
0 0

Golang Iris – ctx.ViewData(key,value) alternative for HTML output

@krokite I don’t know if this is the best way, but this is how I do it and it works:

ctx.ViewData("content", template.HTML("<p>This is HTML content.</p><br><h3>Another String</h3>"))

or create a tmpl func:

tmpl := iris.HTML(...)
tmpl.AddFunc("html", func(text string) template.HTML {
	 return template.HTML(text)
})

ctx.ViewData("text", "<p>This is HTML content.</p><br><h3>Another String</h3>")

{{html .text}}

Don’t forget to import the "html/template" package.

https://github.com/kataras/iris/issues/836

Share and Enjoy !

0Shares
0 0

Routing middleware

package main

import "github.com/kataras/iris/v12"

func main() {
    app := iris.New()
    // or app.Use(before) and app.Done(after).
    app.Get("/", before, mainHandler, after)
    app.Listen(":8080")
}

func before(ctx iris.Context) {
    shareInformation := "this is a sharable information between handlers"

    requestPath := ctx.Path()
    println("Before the mainHandler: " + requestPath)

    ctx.Values().Set("info", shareInformation)
    ctx.Next() // execute the next handler, in this case the main one.
}

func after(ctx iris.Context) {
    println("After the mainHandler")
}

func mainHandler(ctx iris.Context) {
    println("Inside mainHandler")

    // take the info from the "before" handler.
    info := ctx.Values().GetString("info")

    // write something to the client as a response.
    ctx.HTML("<h1>Response</h1>")
    ctx.HTML("<br/> Info: " + info)

    ctx.Next() // execute the "after".
}
https://github.com/kataras/iris/wiki/Routing-middleware

Share and Enjoy !

0Shares
0 0

Moodle URL Redirection

I ended up doing the following to get this to work:

In /opt/bitnami/apache2/conf/httpd.conf, change the following lines:

Comment out
DocumentRoot ‘/opt/bitnami/apache2/htdocs’

Add
DocumentRoot ‘/opt/bitnami/aps/moodle/htdocs’

Comment out
Directory ‘/opt/bitnami/apache2/htdocs’

Add
Directory ‘/opt/bitnami/apps/moodle/htdocs’

Seems to work for me.

https://community.bitnami.com/t/moodle-url-redirection/2376/5

Share and Enjoy !

0Shares
0 0