embedding.html 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. {
  2. title: 'Embedding GoAhead',
  3. crumbs: [
  4. { "Developer's Guide": '../developers/' },
  5. ],
  6. }
  7. <h1 class="title">Embedding GoAhead</h1>
  8. <p>When embedding GoAhead in your application or system, you have two alternatives:</p>
  9. <ol>
  10. <li>Use the existing GoAhead main program and extend GoAhead via Javascript and goforms.</li>
  11. <li>Link the GoAhead library with a custom main program.</li>
  12. </ol>
  13. <a id="goaheadProgram"></a>
  14. <h2 >The GoAhead Program</h2>
  15. <p>The GoAhead product includes a fully-featured HTTP server program called <em>goahead</em> that uses the GoAhead HTTP library.
  16. You can also modify the <em>goahead.c</em> main program to customize according to your specific requirements.
  17. line of code.</p>
  18. <a name="library"></a>
  19. <h2>Embed the GoAhead Library</h2>
  20. <p>You can link the GoAhead library with your application to enable it to listen for HTTP requests and thus
  21. become a HTTP server itself. Embedding the GoAhead library is easy and can be done with as little as one
  22. line of code.</p>
  23. <h3>Linking with the GoAhead Library</h3>
  24. <p>To include the GoAhead library in your program you need to do the following things:</p>
  25. <ol>
  26. <li>Add <b>#include "goahead.h"</b> in your source files.</li>
  27. <li>Add the GoAhead library to your Makefiles or Windows project files. This will mean adding
  28. libgo.lib on Windows or libgo.a on Unix.</li>
  29. <li>Use one of the embedding APIs to create the HTTP server.</li>
  30. </ol>
  31. <h3>Full Control API</h3>
  32. <p>The GoAhead library also provides an extensive API so you can precisely control how
  33. the web server is created and configured.</p>
  34. <p>This example creates a web server using the "server.conf" configuration file and will service events
  35. until terminated.</p>
  36. <pre class="ui code segment">
  37. #include "goahead.h"
  38. int main(int argc, char **argv)
  39. {
  40. if (websOpen("web", "route.txt") &lt; 0) {
  41. error("Can't open the web server runtime");
  42. return 0;
  43. }
  44. if (websListen(":80") &lt; 0) {
  45. mprError("Can't listen on port 80");
  46. return 0;
  47. }
  48. websServiceEvents(NULL);
  49. websClose();
  50. return 0;
  51. }
  52. </pre>
  53. <a name="javascript"></a>
  54. <h2>Extending via Javascript</h2>
  55. <p>The GoAhead Javascript web framework allows customization by direct embedding of Javascript code in
  56. HTML web pages. This code runs on the server-side before rendering the page to the client.
  57. <h3>API Details</h3>
  58. <p>For more details about the embedding API, please consult the <a href="../ref/api/goahead.html">GoAhead
  59. API</a>.</p>