How to implement subdomain-based module in revel - go

I was wondering is there any example or good practice in Revel of making application module, related to subdomain.
For example, we have site.com, which is default application module and want to add an additional admin module for admin.site.com subdomain. The main problem I can see at this point is that we need to
dynamically determine what module should be used (using an interceptor before request)
switch routing in order to avoid collisions (since there may be overlapping routes, such as / for default module and / for admin module)
Does anyone implemented such application architecture in revel? Any related advice would be very helpful.

Related

Springboot application Controllers Designing

i am kind of new with programming, i need help with designig the RestControllers.
I am trying to design a website Using spring boot, the site supposed to have Guests, Users(registerd), Admin, SuperAdmin.
would it be true to use the GuestController as the main one, and let all of the other controllers such as Admin,User,Superadmins extend the GuestController?
Thanks
a more suitable design is to provide a Controller per section (ie Home, News, Search, Admin): each controller is responsible for a section of the web site.
The various user profiles are then used within the controller if you need to differentiate what users can see and do.
There is less code duplication: there is one screen (Search) with one Controller (SearchController) which serves different user profiles. Adding a user profile is straight-forward and does not involve changing the Search code (maybe only adding some extra security in the backend if the new profile can see less or more than the others).
You could use inheritance to define the User Profile: a Guest user is the base profile, but others (Admin) extend it to provide different behaviour.
Hope it helps.

Playframework - internationalization and routes

I need two language versions of my web site which will be located in domainname/lang1/somecontroller and domainname/lang2/somecontroller urls. What architecture of routes file allow me to avoid of duplicating controllers declaration for every language?
* /{language}/MyController Application.MyController
should allow you to access both languages, and you then have access to the language passed in, in the controller, if you wish.

custom header in multitenant application

I have a multi-tenant application with a custom header, basically the logo of the customer and some links are in there.
The header is visible in most modules, but needs to read the logo settings from the database. How do I organise this best?
If I use a component, I have to paste it into all modules. Can I centralise a slot better?
You have 2 options.
First, a component_slot (link goes to 1.2 documentation but it's ok in 1.4). You defined it in for an app and you can re-define it for a specific module.
Second, a basic component. It will perform always the same thing and you can't re-define it. You don't have to paste it in all module, you can call a component from a module X in the template of module Y.

mvc components in codeigniter?

in yii i could have mvc components (acts like an own application). could i have this too in codeigniter?
eg. in SYSTEM/APPLICATION have a folder called COMPONENTS and in there i put stand-alone applications that would be a part of the application. components like ADDRESS BOOK, MAIL, TWITTER and so on. every component folder has folders like: models, views, controllers, config etc.
so a component model extends the application model which in turn extends system's (code igniter) model. the same goes for view and controller.
i've already got a lot of these components which i want to use in codeigniter. is it good idea to place them as i said in SYSTEM/APPLICATION/COMPONENTS or is there best practice for this?
You can do this in CodeIgniter using v1.7.2 or 2.0, but using Packages as Billiam suggested would not work and sadly he is just confusing you.
You are basically looking for a HMVC architecture and this can be provided with a system called Modular Separation.
That works with CodeIgniter 1.7.2 and I have patched it to work with the (still unfinished) CodeIgniter 2.0 branch on the link in the entry.
Not by default in CI 1.7.2, but 'packages' will be available in 2.0.
Added ability to set "Package" paths -
specific paths where the Loader and
Config classes should try to look
first for a requested file. This
allows distribution of
sub-applications with their own
libraries, models, config files, etc.
in a single "package" directory. See
the Loader
class documentation for more
details.
From: http://bitbucket.org/ellislab/codeigniter/src/tip/user_guide/changelog.html
Also, take a look at Modular Extensions - HMVC

(MVC) Controller in shared library?

In MVC, do controllers belong with an application, or can they go into a shared library? For example:
//this is a shared library
LibShared
//these are two apps
appA ->LibShared
appB ->LibShared
Shouldn't each app implement its own MVC and use any shared libraries as perhaps part of the app's logical model or simply another library reference (utilities)?
Also, is there ever a situation in which an MVC Controller is stuck in a shared library? I thought Controllers needed specific views located in a specific app. Meaning, the Controller must go in that app?
Or can Controllers be generic (i.e. shared library)? Doesn't that mean they are no longer Controllers?
I would advise that you should only be separating out your controllers into their own module/package/library (herein referred to as modules) if you have a requirement to do so (i.e. immediate re-use). If no such requirement exists at present then I would defer the decision to when it is required, it sounds in your case you are about to unnecessarily over-engineer. It should in theory be possible to refactor later to a separate modules without much hindrance, however be careful regarding coupling, separating out to different modules doesn't reduce the coupling, look carefully at your dependencies at how much the controller is orientated to one style of view.
one liners answers to your question to your application is
YES, YOU CAN MOVE YOUR CONTROLLER TO A SEPARATE LIBRARY WITHOUT A SINGLE LINE CODE CHANGES.
I suppose any code can go anywhere, what would drive us to put something in a shared library or keep it with the app?
I would consider two things:
1). What's the rate of change? When we change the app overall is this likely to change.
2). Could anything else need to use it? If so when I realease a new version would the other client immediately
Typically a controller would be strongly associated with the application and hence not of much interest to any other app, and it's probably fundamental to the app changing as the app changes. Hence packaging with the app makes sense.
Now if the conroller is somehow more generic, perhaps configuration driven then shared library makes sense.
Controllers does not necessarily needs to be even in the same operating system. You could have a view in Windows, a Controller in Unix and your Model in a Sparc. Remember MVC is just a pattern, a way you could do something which is more robust and easier to modify.
Your controller could be a shared library. Does your controller should be aware of your views? Not necessarily. That depends on how you handle the communication between modules. On a good MVC implementation, modules simply interchange messages or events. So, a View send an event to the Controller, the Controller decides what to do and send a message back. The response of the controller could be something like "Show Window X". Be advised that "Window X" could be interpret by the View module, if the View is an a Web module, then the View just put the proper aspx page. If you have another view who happens to be a web application the renders Form X.
At least in CakePHP and in the architecture that Mike McShaffry explains in his Game Coding Complete book the controller does belong to the application.
However, in both cases the architecture is such that the application inherits the basic functionality of a model, view, and a controller from the framework.
Eg.:
// "super" controller of all applications using this framework
class Controller
// uses basic libraries that allows the inheriting applications to work minimally
class AppController extends Controller
// mainly uses the parent class's methods but can also substitute to using
// additional libraries
By framework here I mean the system that encapsulates the use of libraries. In CakePHP this encapsulation in turn is done by using libraries in the respecting models, views, and controllers. So neither of those components is free from attachment to libraries.
In Mike McShaffry's architecture however, only the controllers and views use libraries. So the models are left uncoupled and are thus highly portable to different applications.

Resources