Creating modules - Sharykhin/go-modular GitHub Wiki

There is "modules" directory in the project (by default under application directory)

  1. Create new directory, the name will be name of module

  2. Then create "controller" and "views" directories inside of your modules

Let's imagine, that we have created user module go into controller directory and create DefaultController.go

package user

import "net/http"
import controller "project/todos/application/controller"

type DefaultController struct {
	controller.BaseController
}

func (ctrl *DefaultController) IndexAction(res http.ResponseWriter, req *http.Request) error {

	if err := ctrl.RenderView(res,req, "modules/user:user", nil, nil); err != nil {
		return err
	}
	return nil
}

func (ctrl *DefaultController) UserProfileAction(res http.ResponseWriter, req *http.Request) error {
	if err := ctrl.Render(res,req, "modules/user:profile", nil, struct {
		UserName string
	}{
		UserName: "John",
	}); err != nil {
		return err
	}
	return nil
}

As you can see on example, we specified package, which is name of our module. We also use views from modules. By the same way, you can initialize a models which are resposible for data of modules.