No person shall be restrained of his liberty but by regular process from a court of justice, authorized by a general law. . . . On complaint of an unlawful imprisonment to any judge whatsoever, he shall have the prisoner immediately brought before him and shall discharge him if his imprisonment be unlawful. The officer in whose custody the prisoner is shall obey the order of the judge, and both judge and officer shall be responsible civilly and criminally for a failure of duty herein.