Skip to content

Instantly share code, notes, and snippets.

@changtimwu
Last active August 29, 2015 14:05
Show Gist options
  • Save changtimwu/5ecf33e7f60b63e48ae5 to your computer and use it in GitHub Desktop.
Save changtimwu/5ecf33e7f60b63e48ae5 to your computer and use it in GitHub Desktop.
swixweb to go plan

base functions

  • static file server for assets and views
    • routes -- done
  • simple views rendering/templating via string replace -- done
  • view rendering
    • header, footer, layout and @body -- done
    • @partial -- done
    • variable translation(ex._initdata) -- done
  • cookie & session
    • session timeout -- no timeout but session & cookie work__
  • login
    • auto redirect when no session data -- done(need integration)
  • require('./utils')
  • sockjs -- done
  • sockjs/smith gateway -- done
  • smith/sockjs event gateway
    • event for sockjs -- done
    • callback can be handled one to many clients -- done
  • auto reconnect to swixcore
    • this must be done because even a simple argument mismatch between server and client can cause disconnection.
  • block non-existed api calls -- done
  • block or auto adjust wrong arguments calls -- need core modification
#browser
ss.emit 'system::get_sys_cfg', "useless arg", (f)->

#core
apidefs:
  get_sys_cfg: (f)->
  • controller
    • controller concept -- done
    • common functions for controllers
      • gethookh -- done
      • withcore -- done
      • coreat -- done

controllers

  • A controller is the pair of an event and its handler(in websocket)
  • A controller mostly carries related http handlers for common function -- done
  • Only of thems also defines socket.io event handlers(aka @on)
    • implement the same thing in sockjs -- done
  • check if the GO can reply http get with header -- done
  { 'Content-Type': 'application/x-yaml'}, 200
  { 'Content-Type': 'application/x-json'}, 200
  • implement @withcore()
  • list of controllers
    • ip_conf ( with @on)
      • get_ipcfg -- not need
      • save_ipcfg -- not need
    • login
      • check @redirect -- done
      • need @session -- done
    • maintain_cfgfile
      • import -- done
      • export -- done
      • export local logs -- done
    • maintain_reboot ( with @on) -- done
      • get_mpart_cfg
      • set_mpart_cfg
    • maintain_upgrade -- done
    • ping ( with @on) -- done
      • run_ping -- done
      • check_ping_msg -- done

help routines

  • search all controllers to include
    • findfns -- not need. GO is static. All controlers will be compiled/linked.
  • determine_core_at -- done
  • process.env.TMP -- done
  • do_loadmenu
    • fliterout_menuitems -- done
    • menu_kill -- done
  • model determination -- done
  • specify route handler and render the page with variables -- done
  • https certificates
  • http port
    • determine_coreat -- done
@changtimwu
Copy link
Author

@changtimwu
Copy link
Author

how a page is rendered original

  • server determine the mainpage to output based on model
  • server render the mainpage
    • translate all partials
    • translate all initial variables ( ex. initdata ) with the json data passed from the handler
    • frame it with layout

some points

  • Since it's SPA, main & login are the only two pages required to do full-set rendering
  • Partials can't do variable translating due to ExpressJS limitation.
    • We didn't finish this in GO yet.
    • Treat a partial as a page without layout. Allow nested partials ?
    • Treat a partial as a page without layout & partial including. Which means partial has only variable translating ability

@changtimwu
Copy link
Author

current bad designs

  • smith framing is not good as original msgpack rpc
  • callback is part of arguments
    • minor error like number of arguments mismatch can make api handler chaos ex
add = (a,b, callback)->
  callback a+b
add 1,2, 3, (ans)->  #the 3 would cause errors
   console.log , "useless arg", (f)->

@changtimwu
Copy link
Author

File upload

Somebody gave a complete example of making GO and Valums uploader work together
https://github.com/ZhuBicen/file-uploader/blob/master/server/golang.go

@changtimwu
Copy link
Author

@changtimwu
Copy link
Author

once
ReadResponseHeader err= EOF ( EOF is returned from msgrecv_bytes())
all subsequential calls fail

This usually happens when a smith call containing wrong format of arguments.

@changtimwu
Copy link
Author

@changtimwu
Copy link
Author

help not accessible

@changtimwu
Copy link
Author

7221 kernel doesn't turn on EPOLL. GO runtime netpoll init would fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment