sample.erl 1018 B

123456789101112131415161718192021
  1. -module(sample).
  2. -behaviour(supervisor).
  3. -behaviour(application).
  4. -compile(export_all).
  5. main(A) -> mad:main(A).
  6. stop(_) -> ok.
  7. start() -> start(normal,[]).
  8. start(_,_) -> case ver() of cow1 -> []; _ ->
  9. cowboy:start_clear(http, [{port, port()}],
  10. #{ env => #{dispatch => n2o_cowboy2:points()} })
  11. end, supervisor:start_link({local,sample},sample,[]).
  12. init([]) -> kvs:join(), {ok, {{one_for_one, 5, 10}, ?MODULE:(ver())() }}.
  13. ver() -> application:get_env(n2o,cowboy_spec,cow2).
  14. cow2() -> [].
  15. cow1() -> [spec()].
  16. port() -> application:get_env(n2o,port,8001).
  17. env() -> [ { env, [ { dispatch, n2o_cowboy:points() } ] } ].
  18. spec() -> ranch:child_spec(http,100,ranch_tcp,[{port,port()}],cowboy_protocol,env()).
  19. rebar3() -> {ok,[{_,R,L}]}=file:consult(code:lib_dir(sample)++"/ebin/sample.app"),
  20. [ application:ensure_started(X) || X <- proplists:get_value(applications,L,[]) ],
  21. application:ensure_started(R).