It there a better way?<br>
Add new MVC routines in a logical and easier way.<br/>
Must support adding new packages easily.<br/>
Every package must have one or more functions.<br/>
The goal is to add functions to a command map that is used to route network

GO can not dynamically link new modules. gowss (github/greenpdx/gowss) is a
MVC system. It parses incoming commands and calls the correct function. I
wanted a way to add new commands easily, this means at startup all the
commands need to be known. I also wanted to be able to add new packages to
the main program. <br/>

I first create a common interface to the commands.<br/>

passed in is a connection arg and a map arg, it returns a map<br>

type Command func( conn *Connection, jin map[string]interface{})

Now I have a module structure:<br/>
type Module struct {<br/>
Name string<br/>
Procs map[string]Command<br>
Data interface{}<br>

it has a name, a map of commands, and user defined data.

The init function is used to setup the module

var Module gows.Module<br/>

func init() {<br>

// create a module structure

mod := gows.Module{<br/>

Name: "mod1",<br/>
Data: nil,<br/>
Procs: make(map[string]gows.Command),<br/>


// Fill in the commands map

mod.Procs["func1"] = func1<br/>
mod.Procs["func2"] = func2<br/>
Module = mod<br/>
fmt.Println("mod1 init",mod.Name, mod.Procs)<br/>

In the main program I add each module to the import.<br/>
import {<br/>




then during program initialization I add the modules functions to the
command list.<br>

func AddMods() {<br/>
gows.Modules["mod1"] = &mod1.Module<br/>

Now when a command comes in I use the function name to call to correct
function from the command list.

Is there a better or easier way to do this?

You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
postedNov 22, '13 at 11:14p
activeNov 22, '13 at 11:14p

1 user in discussion

Sv savage: 1 post



site design / logo © 2022 Grokbase